@Senl
2017-03-24T03:19:57.000000Z
字数 1066
阅读 1188
技术学习
import java.io.*;import java.util.*;public class Test {public static String getIn(){Scanner sc = new Scanner(System.in);String input = sc.nextLine();return input;}public static int getInt(){Scanner s = new Scanner(System.in);int i = s.nextInt();return i;}public static void Write(String fileName, String context ){try {// 打开一个写文件器,构造函数中的第二个参数true表示以追加形式写文件FileWriter writer = new FileWriter(fileName, true);writer.write(context);writer.close();} catch (IOException e) {e.printStackTrace();}}}
import java.io.File;import java.io.IOException;public class TestDrive {public static void main(String[] args) {// TODO Auto-generated method stubString fileName = "F:/Ex/Test.txt";File file=new File(fileName);if(!file.exists()){try {file.createNewFile();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}System.out.println("you can enter sth now"+ "enter 'exit' to stop");String input = Test.getIn();while(!input.equals("exit")){Test.Write(fileName, input+"\r\n");input = Test.getIn();}}}
-见博客