本帖最后由 丶小天 于 2014-2-24 19:46 编辑
- import java.io.FileWriter;
- import java.io.IOException;
- import java.util.Scanner;
- public class TestIO2 {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- System.out.println("请输入信息:");
- String str = sc.nextLine();
- FileWriter fw = null;
- try {
- // 1.创建字符输出流对象,负责向f:\line.txt写入数据
- fw = new FileWriter("f:\\line.txt");
- fw.write(str);
- } catch (IOException e) {
- // TODO: handle exception
- e.printStackTrace();
- } finally {
- try {
- //一定要关闭输出流
- if (null!=fw) {
- fw.close();
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- }
复制代码
|