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 }
  • 相关阅读:
    SmartJS 第一期(0.1)发布
    smartJS 0.1 API 讲解
    smartJS 0.1 API 讲解
    20160113006 asp.net实现ftp上传代码(解决大文件上传问题)
    20151224001 GridView 多按钮的各种使用方法
    20151221001 GridView 模板
    20151218001 雕爷自白:我为什么非要这么干
    20151210001 DataGridView 选中与被选中
    20151126001 网页中嵌入谷歌动态地图
    20151125001 询问对话框 中的文字换行
  • 原文地址:https://www.cnblogs.com/cjunj/p/2755729.html
Copyright © 2011-2022 走看看