File tree Expand file tree Collapse file tree
Section23JavaIOStreams/DemoCodes Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ This Java program reads data from a file named myFile.txt,
2+ character by character, and prints each character on a new line.
3+
4+ It uses FileInputStream and handles I/O exceptions if the file doesn't exist or can't be read.
Original file line number Diff line number Diff line change 1+ //Now Data Read in File
2+ import java .io .IOException ;
3+ import java .io .FileOutputStream ;
4+ import java .io .FileInputStream ;
5+
6+ class Demo2
7+ {
8+ public static void main (String [] args )
9+ {
10+ try
11+ {
12+ int data ;
13+ FileInputStream fin = new FileInputStream ("C://Users//somes//Downloads//NoteApp//JavaEvolution-Learning-Growing-Mastering//Section23JavaIOStreams//DemoCodes\\ TXT Files\\ Demo2.txt" );
14+ while ( (data = fin .read ()) != -1 )
15+ {
16+ System .out .println ( (char ) data );
17+ }
18+ }
19+ catch (IOException e )
20+ {
21+ System .out .println (e );
22+ }
23+ }
24+ }
You can’t perform that action at this time.
0 commit comments