Skip to content

Commit 59e2316

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

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
//This Java program reads a text file character by character using FileInputStream and prints its content to the console.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import java.io.FileInputStream;
2+
public class Demo1
3+
{
4+
public static void main(String args[]){
5+
try
6+
{
7+
FileInputStream fin=new FileInputStream("C://Users//somes//Downloads//NoteApp//JavaEvolution-Learning-Growing-Mastering\\Section23JavaIOStreams\\DemoCodes\\TXT Files\\Demo1.txt");
8+
int i=0;
9+
10+
while((i=fin.read())!=-1)
11+
{
12+
System.out.print((char)i);
13+
}
14+
15+
/*
16+
Reads the file one byte at a time.
17+
fin.read() returns an int representing the byte value. It returns -1 when the end of the file (EOF) is reached.
18+
(char)i converts the byte into a character, and it prints it to the console.
19+
So, this part prints the entire content of the file.
20+
*/
21+
fin.close();
22+
}
23+
catch(Exception e)
24+
{
25+
System.out.println(e);
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)