How To Read a text file by ByteArrayInputStream in java
Code:
import java.util.*;
import java.io.*;
import java.io.*;
class test7
{
public static void main(String arg[])
{
try
{
System.out.println(" ");
FileInputStream fis=new FileInputStream("text.txt");
BufferedInputStream buf= new BufferedInputStream(fis);
int j;
while((j=buf.read())!=-1)
{
char c[]=new char[1024];
byte b[]=new byte[1024];
for(int i=0;i<c.length;i++)
{
c[i] = (char)j;
b[i]=(byte)c[i];
}
for(int i2=0;i2<1;i2++)
{
ByteArrayInputStream bis1 = new ByteArrayInputStream(b);
int k=0;
k=bis1.read();
System.out.print((char)k);
}
}
}
catch(Exception e)
{
System.out.println("Exception msg: "+e);
}
}
}
{
public static void main(String arg[])
{
try
{
System.out.println(" ");
FileInputStream fis=new FileInputStream("text.txt");
BufferedInputStream buf= new BufferedInputStream(fis);
int j;
while((j=buf.read())!=-1)
{
char c[]=new char[1024];
byte b[]=new byte[1024];
for(int i=0;i<c.length;i++)
{
c[i] = (char)j;
b[i]=(byte)c[i];
}
for(int i2=0;i2<1;i2++)
{
ByteArrayInputStream bis1 = new ByteArrayInputStream(b);
int k=0;
k=bis1.read();
System.out.print((char)k);
}
}
}
catch(Exception e)
{
System.out.println("Exception msg: "+e);
}
}
}

Comments
Post a Comment