zoukankan      html  css  js  c++  java
  • 9、将标准字符流写到文件中

     1 package Io;
     2 
     3 import java.io.BufferedReader;
     4 import java.io.BufferedWriter;
     5 import java.io.FileNotFoundException;
     6 import java.io.FileWriter;
     7 import java.io.IOException;
     8 import java.io.InputStreamReader;
     9 import java.io.PrintWriter;
    10 
    11 public class TestHtml {
    12     public static void main(String[] args) {
    13         BufferedReader br = null;
    14         PrintWriter pw = null;
    15         try {
    16             br = new BufferedReader(new InputStreamReader(System.in));
    17             pw = new PrintWriter(new BufferedWriter(new FileWriter("G:\IoTest\2.html")));
    18             String str = null;
    19             while ((str = br.readLine()) != null) {
    20                 if (str.equals("exit")) {
    21                     System.out.println("感谢使用");
    22                     break;
    23                 }
    24                 pw.println(str);
    25             }
    26         } catch (FileNotFoundException e) {
    27             e.printStackTrace();
    28         } catch (IOException e) {
    29             e.printStackTrace();
    30         } finally {
    31             if (br != null)
    32                 try {
    33                     br.close();
    34                 } catch (IOException e) {
    35                     e.printStackTrace();
    36                 }
    37         }
    38         if (pw != null)
    39             pw.close();
    40     }
    41 }
  • 相关阅读:
    python-高阶函数(map,reduce,filter)
    python-函数(补充)
    python-局部变量与全局变量
    python-函数
    字符串格式化
    pycharm2019.1激活方法(亲测可用)
    python-集合
    python-字典
    keepalivd 配置
    zabbix3 agent端安装
  • 原文地址:https://www.cnblogs.com/Akke/p/5020927.html
Copyright © 2011-2022 走看看