1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
/* Write byte array to a file using FileOutputStream This example shows how to write a byte array to a file using write method of Java FileOutputStream object. */ import java.io.*; public class WriteByteArrayToFile { public static void main(String[] args) { String strFilePath = "C://FileIO//demo.txt"; try { FileOutputStream fos = new FileOutputStream(strFilePath); String strContent = "Write File using Java FileOutputStream example !"; /* * To write byte array to a file, use * void write(byte[] bArray) method of Java FileOutputStream class. * * This method writes given byte array to a file. */ fos.write(strContent.getBytes()); /* * Close FileOutputStream using, * void close() method of Java FileOutputStream class. * */ fos.close(); } catch(FileNotFoundException ex) { System.out.println("FileNotFoundException : " + ex); } catch(IOException ioe) { System.out.println("IOException : " + ioe); } } } |
I was playing with my code for 24 hours but could not fix the problem. I looked at this example and I was able to fix my problem. ( I was trying to write a new line to a binary file)
thanks
A.A
nice codes. . . . .can help more a lot?.
I learn many things from this site using different examples. i solved many problems , what i faced earlier. thanks to all
Was looking exactly for this example. Thanks.