my intent for this program was to create a simple program that takes input from the terminal line by line, and stores it into a file in the same fashion, ending when the user inputs "end".
I'm confused about why... 1) the while loop does not end when the user inputs "end" 2) the data is not written to the file (I've checked, it doesn't for whatever reason)
Edit: the answer has been found already! For those just arriving, my while condition should have been !temp.equals("end")
public static void main(String[] args) throws IOException{
Scanner in = new Scanner(System.in);
System.out.println("Type in data and it will be written to a file");
System.out.println("filename = blah.txt");
String temp, filename="blah.txt";
PrintWriter outfile = new PrintWriter(new FileWriter(filename));
System.out.println("enter next line... \"end\" to exit");
temp=in.nextLine();
while(temp!="end"){
outfile.println(temp);
System.out.println("enter next line... \"end\" to exit");
temp=in.nextLine();
}
outfile.close();
}