OutputStreamWriter
In this chapter you will learn:
Use OutputStreamWriter
An OutputStreamWriter
is a bridge from
character streams to byte streams:
Characters written to it are encoded into bytes
using a specified charset.
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
/* ja v a 2 s . c om*/
public class Main {
public static void main(String[] args) throws Exception {
try {
FileOutputStream fos = new FileOutputStream("test.txt");
Writer out = new OutputStreamWriter(fos, "UTF8");
out.write("java2s.com");
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Next chapter...
What you will learn in the next chapter:
Home » Java Tutorial » Reader Writer