FileOutputStream.write(int b)
方法具有以下语法。
public void write(int b) throws IOException
示例
在下面的代码显示如何使用FileOutputStream.write(int b)
方法。
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
byte b = 66;
int i = 0;
FileOutputStream fos = new FileOutputStream("C://test.txt");
fos.write(b);
fos.flush();// => W ww .Y I I BA I .c Om
FileInputStream fis = new FileInputStream("C://test.txt");
// read till the end of the file
while ((i = fis.read()) != -1) {
// convert integer to character
char c = (char) i;
System.out.print(c);
}
}
}