[code=Java][/code]import java.io.*;
public class File_Write {
public static void main(String [] args){
try{
File a = new File("like.txt");
FileWriter b = new FileWriter(a);
BufferedWriter write_sentence = new BufferedWriter(b);
String cache = null;
String checking = null;
while(cache !="exit" && checking !="yes"){
java.util.Scanner in = new java.util.Scanner(System.in);
cache = in.nextLine();
if(cache =="exit"){
System.out.println("Make sure exit? yes/no");
checking = in.nextLine();
}
else{
write_sentence.write(cache);
}
}
write_sentence.close();
}
catch(Exception ex){
ex.printStackTrace();
}
}
}
这是输入中一段话,如果输入exit,就判断是否完成输入,再次输入yes就完成写入。可是结束不了输入操作。。。。
------解决方案--------------------
字符串对比请使用equals
------解决方案--------------------
JAVA中除了原始类型用 ==
字符串要用String.equal方法比较
------解决方案--------------------
while(!"exit".equals(cache) && !"yes".equals(checking)){
if("exit".equals(cache)){