package cn.jbit.inputstream;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class Test {

    /**
     * @param args
     */
    public static void main(String[] args) {

        try {
            // 创建一个FileInputStream对象

            File file = new File("D:\\c.txt");

            FileInputStream fileInputStream = new FileInputStream(file);
            byte[] bs = new byte[100];
            
            // 将文件的内容读入 数组中
            fileInputStream.read(bs);
            
            // 将byte数组转成String
            String str = new String(bs);
            System.out.println(str);

            // 写入文件
            FileOutputStream fileOutputStream = new FileOutputStream(
                    "D:\\c1.txt", true);
            fileOutputStream.write(bs, 0, bs.length);

        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

}

 

相关文章:

  • 2021-09-03
  • 2022-12-23
  • 2021-09-01
  • 2021-10-22
  • 2022-12-23
  • 2022-12-23
  • 2022-03-01
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-22
  • 2021-11-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案