Skip to content

Commit 2e7170e

Browse files
committed
Added Practice Demo Code2.
Signed-off-by: Someshdiwan <Someshdiwan369@gmail.com>
1 parent 59e2316 commit 2e7170e

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
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.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
}

0 commit comments

Comments
 (0)