// There Reading the text file FileInputStream:
import java.io.*;
class ReadFile
{
public static void main(String[]arr)
throws IOException
{
// attch the file to FileInputStream
FileInputStream fin=new FileInputStream("myfile.txt");
System.out.println("FileContents:");
// raed Character from FileInputStream and write them
//to monitor .Repeat this till the end of file,
int ch;
while(( ch=fin.read())!=-1)
System.out.print((char)ch);
// close the file
fin.close();
}
}
That is Output
E:\ShashiJava>javac ReadFile.java
E:ShashiJava>java ReadFile
Hello I am Shahsi This File No Is One
import java.io.*;
class ReadFile
{
public static void main(String[]arr)
throws IOException
{
// attch the file to FileInputStream
FileInputStream fin=new FileInputStream("myfile.txt");
System.out.println("FileContents:");
// raed Character from FileInputStream and write them
//to monitor .Repeat this till the end of file,
int ch;
while(( ch=fin.read())!=-1)
System.out.print((char)ch);
// close the file
fin.close();
}
}
That is Output
E:\ShashiJava>javac ReadFile.java
E:ShashiJava>java ReadFile
This is my file line one
This is my file line two Hello I am Shahsi This File No Is One
Hello I am Shahi This File No Is Two
0 comments:
Post a Comment