Java Tutorial 18 - Reading and Writing Files in Java

preview_player
Показать описание
This video is intended for students of King Faisal University - College of Computer Science and Information Technology (CCSIT).

Students will learn the simplest methods in reading and writing text files in Java using File, Scanner, FileWriter, and BufferedWriter classes in Java.
Рекомендации по теме
Комментарии
Автор

Great video, after scouring the internet for a video that explains how to read through a file this is the only one that did so well!

cathalharrington
Автор

Hi bongobl! Yes, you're correct, it will also work. The flush method moves whatever is in the buffer to the destination (output file). So you may do that one by one inside the loop or one time after the loop. Your suggestion is good if you don't expect that the buffer will become full.

KFUccsit
Автор

Btw, one thing we didn't include here is the close() method which should be written after the loop. If you will do what you suggested, you don't have to write the flush() method anymore as the close() method flushes the buffer already and cleans up all the resources used.

KFUccsit
Автор

For beginner, This video is very useful .

mohammedrahman
Автор

oh I see, ur way doesn't risk filling up the bufferedwriter, thanks Aly Al-Rapsing

bongobl
Автор

For your file writer, you put the flush method call inside the for loop making it have to flush every time i increments, can't you just flush after the loop?

bongobl
Автор

Hi sir, how to read file and pass information line by line to display in JTextField or JTextarea, let say i have multi line of text in the a text file, , and i want it by line to display in difference JTextField(line1 to JTextField1, and Line2 to JTextField2....so on). hope you can help thanks

samithfp
Автор

thank you very much you helped m very much :-)

mate
Автор

file file = new file("d:/filename.txt");
we must enter d: ?? d: is meaning ..to locate where the file is it? what about we not put d:?

ahmadsolehin