i want to read from a file and store it in a single string variable. but the file size is to large can any one help me....................?
read from a file and store it in a string
Page 1 of 17 Replies - 176 Views - Last Post: 16 August 2012 - 06:47 AM
Replies To: read from a file and store it in a string
#2
Re: read from a file and store it in a string
Posted 15 August 2012 - 10:54 AM
read it line by line? character by character?
there are many ways
there are many ways
#3
Re: read from a file and store it in a string
Posted 15 August 2012 - 11:02 AM
#4
Re: read from a file and store it in a string
Posted 15 August 2012 - 11:33 AM
show us the code. i just told you the solution and you did not get it at all
#5
Re: read from a file and store it in a string
Posted 15 August 2012 - 03:04 PM
What do you mean by the file size is too large? If the file is too big to fit in memory then you cannot store it all in a variable.
#6
Re: read from a file and store it in a string
Posted 15 August 2012 - 03:13 PM
#7
Re: read from a file and store it in a string
Posted 16 August 2012 - 06:41 AM
darek9576, on 15 August 2012 - 11:33 AM, said:
show us the code. i just told you the solution and you did not get it at all
inp="";
try
{
FileInputStream fStream=new FileInputStream("C:/Users/RAMESH/Desktop/hai.txt");
DataInputStream in=new DataInputStream(fStream);
BufferedReader br=new BufferedReader(new InputStreamReader(in));
String strLine;
while((strLine=br.readLine())!=null)
{
inp=inp+strLine;
}
System.out.println(inp);
in.close();
}
catch(Exception e)
{
System.out.println("error"+e.getMessage());
}
here the file hai is about 15kb size. in further i want to do some operations on the string inp but it showing error like exceded string limit...........can any one help me for this problem
#8
Re: read from a file and store it in a string
Posted 16 August 2012 - 06:47 AM
Your error is not likely caused by the size of the file/string as much as the highly inefficient method you're using to create the String. String concatenation should be avoided at the best of times, but your code will cause over-allocation of memory and (possibly) the creation of huge numbers of string buffer -like objects.
Use the code i posted.
Use the code i posted.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote






|