java去除以张开头的人名_java写一个程序,允许用户依次输入多个姓名和住址,并能将用户的输入保存到文件中。用户输入“quit”退...

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();

}

}

}

}

  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值