A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© yan1992924 中级黑马   /  2016-3-31 21:41  /  729 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文



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

评分

参与人数 2黑马币 +10 收起 理由
大梦想家 + 4 赞一个!
shuiguang + 6 赞一个!

查看全部评分

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马