您的位置:首页 > 编程语言 > PHP开发

处理流中的转换流。InputStreamReader & OutputStreamWriter

2016-04-26 11:17 656 查看
import java.io.*;
public class TestTransform {

public static void main(String[] args) {
try{
//create a text file
OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("E:\\sync\\Java\\TestTransform\\encode.txt"));
osw.write("Microsoft C# vs Oracle Java");
System.out.println(osw.getEncoding());
osw.flush();
osw.close();
//read the text file
FileReader fr = new FileReader("E:\\sync\\Java\\TestTransform\\encode.txt");
int call = 0 ;
while((call = fr.read()) != -1){
System.out.print((char)call);
}
fr.close();
System.out.println("\n");
//change the Encodeing_text file
osw = new OutputStreamWriter(new FileOutputStream("E:\\sync\\Java\\TestTransform\\encode.txt",true),"ISO-8859-1");
osw.write(". Cuz the 2nd argument, there is an new String appended in the end.");
System.out.println(osw.getEncoding());
osw.flush();
osw.close();
//display final text file
FileReader ffr = new FileReader("E:\\sync\\Java\\TestTransform\\encode.txt");
while((call = ffr.read()) != -1){
System.out.print((char)call);
}
ffr.close();
}catch(IOException ioe){
ioe.printStackTrace();
}
}
}

FileOutputStream(String string,boolean)的用法



OutputStreamWriter制定编码的用法
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息