javaIO 字符流读写

package com.io.test;

 

import java.io.File;

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.InputStream;

import java.io.InputStreamReader;

import java.io.OutputStream;

import java.io.OutputStreamWriter;

import java.io.Reader;

import java.io.Writer;

 

/**

 * @author Administrator 字符多读取

 */

public class InputStreamReaderTest {

public static void main(String[] args) {

// TODO Auto-generated method stub

File file = new File("src/bb.txt");

InputStream is = null;

OutputStream os = null;

Reader rd = null;

Writer writer = null;

try {

is = new FileInputStream(file);//输入流

rd = new InputStreamReader(is);//输出流

char c[] = new char[is.available()];

rd.read(c, 0, c.length);

 

os = new FileOutputStream("d://dd.txt");//输出到文件里面

writer = new OutputStreamWriter(os);

writer.write(c);

writer.flush();

//关闭流

is.close();

rd.close();

os.close();

writer.close();

} catch (FileNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}


你可能感兴趣的:(java,C++,c,OS,C#)