Java OutputStream.write(int b)
Syntax
OutputStream.write(int b) has the following syntax.
public abstract void write(int b) throws IOException
Example
In the following code shows how to use OutputStream.write(int b) method.
/*from ww w.jav a 2 s .c o m*/
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
public class Main {
public static void main(String[] args) {
try {
OutputStream os = new FileOutputStream("test.txt");
InputStream is = new FileInputStream("test.txt");
os.write(70);
os.write(71);
for (int i = 0; i < 2; i++) {
System.out.print((char) is.read());
}
os.close();
is.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
The code above generates the following result.
Home »
Java Tutorial »
java.io »
Java Tutorial »
java.io »