First of all, remember that it is InputStreamReadernot so effective, you should wrap it around the object BufferedReaderfor maximum performance.
With that in mind, you can do something like this:
public String readLines(InputStreamReader in)
{
BufferedReader br = new BufferedReader(in);
StringBuffer sb = new StringBuffer(5000);
try
{
int linesPerRead = 100;
for (int i = 0; i < linesPerRead; ++i)
{
sb.append(br.readLine());
sb.append('\n');
}
}
catch (Exception e)
{
e.printStackTrace();
}
return sb.toString();
}
Note that the readLine()return nullis EOF, so you should check and take care of it.
source
share