Home › Forums › General Chat › Java I/O › Reply To: Java I/O
BufferedWriter out = new BufferedWriter(new FileWriter(“outfilename”));
out.write(“aString”);
out.close();
}
catch (IOException e) {
}
You get that right? we’re creating a new BufferedWriter object, which is then going to write to a filename that is currently known as “outfilename”, and then we’re going to write in “aString” into that file, and then close the buffer.
We catch any exceptions and we don’t do anything with it.
And we end the block.
So all of the stuff after the ‘.’ are just methods included in the BufferedWriter class – they’re pre-written so you don’t have to. It just depends on what you use to do what.
I don’t know what you’re trying to accomplish still.
Like the same thing for reading:
What it does is it creates a new BufferedWriter object, then it creates a new string that’s set as null.
Then it reads the file that’s designated line per line, replaces the ‘null’ with that particular line, then spits it back out.
The file path is often in the same folder, unless you specify a new location for it to look it.
This man speaks as much of the truth as we can give you without starting from the beginning.