我的算法是这样的 写入一行敲一次回车保存一次- /*
- * 有几种方法将字符串存入文件,并能一次一行保存?
- *
- * */
- public class Demo {
- public static void main(String[] args) throws Exception{
- System.out.println("请输入一句话");
- BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
- // FileOutputStream write = new FileOutputStream("D:\\copy_1.txt");
- BufferedWriter writee = new BufferedWriter(new FileWriter(new File("D:\\copy_1.txt")));
-
- while(true){
- String str = input.readLine();
- writee.write(str);
- writee.newLine();
- if(str=="over"){
- break;
- }
- }
- System.out.println("GameOver");
-
- }
- }
复制代码 |