I want to take input from keyboard in my java program until the user type abc
Here is the code which i have written but it doesn't work. the program continues to take input from keyboard even after i have typed abc and lastly I have to close the program by myself. It takes in input from keyboard and write it on a file named file1.txt
import java.io.*;
import java.util.*;
public class io {
public static void main(String args[]) {
try {
BufferedWriter writer = new BufferedWriter(new FileWriter("file1.txt", true));
Scanner keyboard = new Scanner(System.in);
do {
writer.write(keyboard.next());
writer.newLine();
} while (keyboard.next() != "abc");
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}