zoukankan      html  css  js  c++  java
  • java IO之FileInputStream和FileOutputStream

     1 package com.io.test;
     2 
     3 import java.io.FileInputStream;
     4 import java.io.FileNotFoundException;
     5 import java.io.FileOutputStream;
     6 import java.io.IOException;
     7 
     8 import org.junit.Test;
     9 
    10 public class TestFileStream {
    11 
    12     @Test
    13     public void testFileInputStream() {
    14         try {
    15             FileInputStream is = new FileInputStream("E:/1.txt");
    16             int b = 0;
    17             int num = 0;
    18             while ((b = is.read()) != -1) {
    19                 System.out.print((char) b);
    20                 num++;
    21             }
    22             is.close();
    23             System.out.println();
    24             System.out.println("共输出" + num + "个字符");
    25         } catch (FileNotFoundException e) {
    26             e.printStackTrace();
    27         } catch (IOException e) {
    28             e.printStackTrace();
    29         }
    30     }
    31     
    32     
    33     @Test
    34     public void testFileOutputStream() {
    35         try {
    36             FileInputStream is = new FileInputStream("E:/1.txt");
    37             FileOutputStream os = new FileOutputStream("E:/2.txt");
    38             int b = 0;
    39             while ((b = is.read()) != -1) {
    40                 os.write(b);
    41             }
    42             is.close();
    43             os.close();
    44             
    45         } catch (FileNotFoundException e) {
    46             e.printStackTrace();
    47         } catch (IOException e) {
    48             e.printStackTrace();
    49         }
    50 
    51     }
    52 }
  • 相关阅读:
    Oracle SQL语句大全—查看表空间
    Class to disable copy and assign constructor
    在moss上自己总结了点小经验。。高手可以飘过 转贴
    在MOSS中直接嵌入ASP.NET Page zt
    Project Web Access 2007自定义FORM验证登录实现 zt
    SharePoint Portal Server 2003 中的单一登录 zt
    vs2008 开发 MOSS 顺序工作流
    VS2008开发MOSS工作流几个需要注意的地方
    向MOSS页面中添加服务器端代码的另外一种方式 zt
    状态机工作流的 SpecialPermissions
  • 原文地址:https://www.cnblogs.com/cjunj/p/2755727.html
Copyright © 2011-2022 走看看