Don't ever use string concatenation for this kind of purpose.
Instead of String
, use StringBuffer
class for this purpose.
Consider Following example:
public StringBuffer readFile()
{
StringBuffer tempSB = new StringBuffer();
try
{
FileReader file = new FileReader(FILE_LOCATION);
BR = new BufferedReader(file);
String strLine = null;
while((strLine = BR.readLine()) != null)
{
tempSB.append(strLine);
tempSB.append("\n");
}
}
catch(Exception e)
{
}
return temp;
}
This will save your heap memory.