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制定編碼的用法