import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Scanner;
public class Test4 {
/**
* @param args
* 将键盘录入的数据拷贝到当前项目下的text.txt文件中,键盘录入数据当遇到quit时就退出
* @throws IOException
*/
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
FileOutputStream fos = new FileOutputStream("text.txt");
System.out.println("请输入:");
while(true) {
String line = sc.nextLine();
if("quit".equals(line))
break;
fos.write(line.getBytes());
fos.write("\r\n".getBytes());
}
fos.close();
}
}
附上运行图: