How To Read a text file by ByteArrayInputStream in java




Code: 

import java.util.*;
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);
  }
 }
}


Comments

Popular posts from this blog

Java Project of restaurant dish menu System with File handling java IO | With Code

Custom MenuItem with Notification on it

Encoded Password Save in database | asp.net with c#