Writing in a file with Java
The task of writing a file with Java is very simplified, with input / output streams. This is a group of core classes used for I / O, and include classes serialization that allows a program to read and write to all objects of a stream. Many methods of writing to a file can be employed and which are included in the package java.io. Here is a simple example of writing to a file with Java.
Imports of all kinds necessary. We import every single class for purposes of illustration, but could import whole package with the statement “import java.io. *.”
Declaring an object FileInputStream for the entry and exit records and exemplify with the input and output file names (input.txt and output.txt, respectively).
Use the method of writing class FileOutputStream to write in the output file. Other methods are available to write a file, but writing is used here as the simplest possible example.
Notice how the program stays in a loop that reads one byte of inflow and writes the byte to the output stream until the end of the input file is reached.
See the complete code for this example:
import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException;
WriteBytes public school (public static void main (String [] args) throws IOException (FileInputStream in = null; FileOutputStream out = null; try (int i; = new FileInputStream ( “input.txt”); out = new FileOutputStream ( “Output.txt”);
While ((i = in.read ())! = -1) (Out.write (i);)) (if finally (! = Null) (in.close ( );) If (! = Null) (Out.close ();))))
Featured Links:
Proven Money Maker At $9,547 A Day.
Burn The Fat - Top Selling Fat Loss Ebook Since 2003.
Have You Ever Stayed Awake at Night Stressing About Whether or Not Your Marriage Will Last ... And What You Can Possibly Do to Save It?
Scan your computer for hidden AdWare and Spyware, Remove them permanently.
Join the Internet revolution and start downloading free movies and more!
Internet Marketer Gets $87 Million in Google Pay-Per-Click Ads FREE! ... And Makes Over $314 Million as a Result! ...And Now He's Going to Give You This Same Secret for Next to Nothing!








Leave a comment
You must be logged in to post a comment.