zoukankan      html  css  js  c++  java
  • java IO之FileReader和FileWriter

     1 package com.io.test;
     2 
     3 import java.io.FileNotFoundException;
     4 import java.io.FileReader;
     5 import java.io.FileWriter;
     6 import java.io.IOException;
     7 
     8 import org.junit.Test;
     9 
    10 public class TestFileReaderAndWriter {
    11     @Test
    12     public void testFileReader() {
    13         try {
    14             FileReader fr = new FileReader("E:/1.txt");
    15             int ln = 0;
    16             while ((ln = fr.read()) != -1) {
    17                 System.out.print((char)ln);
    18             }
    19             fr.close();
    20         } catch (FileNotFoundException e) {
    21             e.printStackTrace();
    22         } catch (IOException e) {
    23             e.printStackTrace();
    24         }
    25     }
    26     @Test
    27     public void testFileWriter(){
    28         try {
    29             FileReader fr = new FileReader("E:/1.txt");
    30             FileWriter fw = new FileWriter("E:/3.txt");
    31             int ln = 0;
    32             while((ln = fr.read()) != -1){
    33                 fw.write((char)ln);
    34             }
    35             fr.close();
    36             fw.close();
    37         } catch (FileNotFoundException e) {
    38             e.printStackTrace();
    39         } catch (IOException e) {
    40             e.printStackTrace();
    41         }
    42     }
    43 }
  • 相关阅读:
    C++使用静态类成员时出现的一个问题
    C++中的const_cast
    【位运算与嵌入式编程】
    电压取反电路
    bzoj4769
    初赛
    noip2011day2
    uva1252
    codeforces 703d
    poj[1734]
  • 原文地址:https://www.cnblogs.com/cjunj/p/2755729.html
Copyright © 2011-2022 走看看