赞
踩
import java.io.*;
public class FileIn {
public static void main(String []args) throws IOException {
String name;
String address;
String q = null;
File f=new File("C:\\Users\\Media\\Desktop","file.txt");
//BufferedWriter fout=new BufferedWriter(new FileWriter(f));
FileWriter fout = new FileWriter(f, true);
//BufferedWriter fout = new BufferedWriter(new
OutputStreamWriter(
//new FileOutputStream(f, true)));
//PrintStream fout=new PrintStream(new FileOutputStream(f));
//System.setOut(fout);
fout.write("fasfas");
fout.flush();
//每次写入数据必须加filewriter.flush(),才能及时更新文件!!!!
Scanner sc=new Scanner(System.in);
while(true){
System.out.println("请依次输入姓名与地址:");
name=sc.nextLine();
if("quit".equals(name)){
fout.close();sc.close();System.exit(0);
}
else{
fout.write(name);
fout.flush();
}
address=sc.nextLine();
if("quit".equals(address))
{fout.close();sc.close();System.exit(0);}
else{
fout.write(address);
fout.flush();
}
}
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。