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 }
  • 相关阅读:
    CodeForces 955D
    C# 基础复习三 C#7
    C#各版本新功能 C#7.3
    同步基元概述
    C#各版本新功能 C#7.1
    C#各版本新功能 C#6.0
    C#各版本新功能 C#7.0
    js加载事件和js函数定义
    java.sql.SQLException: Access denied for user 'root '@'localhost' (using password: YES) 最蠢
    消息管理-activemq
  • 原文地址:https://www.cnblogs.com/cjunj/p/2755729.html
Copyright © 2011-2022 走看看