当前位置 : 主页 > 编程语言 > java >

Java中的IO操作 RWByCharStream

来源:互联网 收集:自由互联 发布时间:2022-09-02
import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.Unsu

 

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;


public class RWByCharStream {

public static void main(String[] args) {
try {


//File file = new File("java.txt");
FileInputStream fis = new FileInputStream("java.txt");
FileOutputStream fos = new FileOutputStream("java_new.txt");
InputStreamReader isr = new InputStreamReader(fis, "UTF-8");
OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF-8");
char input[] = new char[100];
int l = 0;
while ((l = isr.read(input)) != -1) {
//String inputString = new String(input,0,l);
osw.write(input,0,l);
}
isr.close();
fis.close();
osw.close();
fos.close();
System.out.println("done");

} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

}

}

 

上一篇:springMVC对静态资源放行的两种方式
下一篇:没有了
网友评论