Skip to content

Java – read from text file and display string at JSP

November 6, 2007


public static String readFromFile(String filename)
{
String line;
StringBuffer sb = new StringBuffer();
String fileStr ="";
try
{
filename ="C:\\a.txt";
BufferedReader in = new BufferedReader(new FileReader(filename));

while ((line = in.readLine()) != null)
{
sb.append(line);
//so that will go new line at jsp
sb.append(“<br/>”);
}

in.close();
fileStr = sb.toString().trim();
}
catch (FileNotFoundException e)
{
logger.error(“Error reading file: file not found exception: ” + e);
e.printStackTrace();
}
catch (IOException e)
{
logger.error(“Error reading file IO exception: ” + e);
e.printStackTrace();
}
return fileStr;
}

From → Java

One Comment
  1. It is absolutely obvious that young people have very little knowledge of personal finance. Even some of the college students think that the money from credit cards is free. And not only young people are ignorant about credit cards. The best way for them to choose the right credit card is read the details. There is a great site to compare credit card offers

    reastablish your credit

Leave a comment