WriteBytes

来源:互联网 发布:windows无法打开打印机 编辑:程序博客网 时间:2024/06/06 20:59
/** * 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");}}}

0 0