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;
//from j a v a 2 s . com
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:
- How to use RandomAccessFile
- How to create a RandomAccessFile in read mode
- How to seek position with RandomAccessFile
- How to get file length from RandomAccessFile
- How to read into a byte array
- Read a single byte
- Seek position in a RandomAccessFile
- How to write byte array into RandomAccessFile
- How to write a String to a RandomAccessFile
Home » Java Tutorial » I/O