//Usage of FileInputStream Class
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.IOException;
public class FileInputStreamDemo
{
public static void main(String args[])throws IOException
{
int size;
String s1="";
InputStream f1=new FileInputStream("file1.txt"); //reads text as a byte from the existing file in the current path
System.out.println("Total size:" + (size=f1.available()));
for(int i=0;i<size;i++)
{
//if(i==10)
//f1.skip(4); //It skips the 4 characters from 10th position
System.out.print((char)f1.read());
}
f1.close();
}
}
Output:
Total size:34
Hello Welcome to File Handling Bye
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.IOException;
public class FileInputStreamDemo
{
public static void main(String args[])throws IOException
{
int size;
String s1="";
InputStream f1=new FileInputStream("file1.txt"); //reads text as a byte from the existing file in the current path
System.out.println("Total size:" + (size=f1.available()));
for(int i=0;i<size;i++)
{
//if(i==10)
//f1.skip(4); //It skips the 4 characters from 10th position
System.out.print((char)f1.read());
}
f1.close();
}
}
Output:
Total size:34
Hello Welcome to File Handling Bye
No comments:
Post a Comment