/**
* Use FileOutputStream to write the bytes to a file.
*/
package FileIO;
import java.io.*;
/**
* @author Administrator
*
*/
public class WriteBytes {
/**
* @param args
*/
public static void main(String[] args) {
// This array contains the ASCII code for the
// letters A through J.
byte[] vals = { 65, 66, 67, 68, 69, 70, 71, 72, 73, 74 };
FileOutputStream fout;
try {
// Open output file.
fout = new FileOutputStream("Test.dat");
} catch (FileNotFoundException exc) {
System.out.println("Error Opening Output File");
return ;
}
try {
// Write every other value in the vals array to the file.
/*
for (int i = 0; i < vals.length; ++i)
fout.write(vals[i]);
*/
fout.write(vals);
} catch (IOException exc) {
System.out.println("Error Writing File");
}
try {
fout.close();
} catch (IOException exc) {
System.out.println("Error Closing File");
}
}
}
WriteBytes
最新推荐文章于 2021-03-13 23:32:24 发布