How To Read a text file by CharArrayReader in java


Source Code:


import java.io.*;

public class CharArrayEx1
{
public static void main(String args[]) throws Exception
{
File f= new File("Demo3.txt");
FileReader fR= new FileReader(f);
BufferedReader bR= new BufferedReader(fR);
int len=(int)f.length();
//System.out.println("length: "+len);
char[] ch1=new char[len+1];
for(int j=0;j<len;j++)
{
int i;
i=bR.read();

ch1[j]=(char)i;
}

CharArrayReader cR= new CharArrayReader(ch1);
int k=0;
while((k=cR.read())!=-1)
{
char ch2=(char)k;
System.out.print(ch2);
}
}
}



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#