import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Scanner;
public class WriteString {
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
StringBuffer sb = new StringBuffer();
System.out.println("-------输入x结束输入!-------");
String t = scanner.nextLine();
while(t != null && !t.equals("x")){
sb.append(t+"\r\n");
t = scanner.nextLine();
}
String path = "D:\\down\\test.txt";
write(path,sb.toString());
}
public static void write(String path,String s){
File file = new File(path);
try {
OutputStream output = new FileOutputStream(file);
byte[] bt = s.getBytes();
output.write(bt);
output.close();
} catch (IOException e) {
System.out.println("文件不存在");
e.printStackTrace();
}
}
}