import java.io.*; public class IoTest { public static void main(String[] args) { String s; s=calculate(); System.out.println(s); } static String calculate() { StringBuffer sb=new StringBuffer(""); try{ FileReader reader = new FileReader("words.txt"); BufferedReader br = new BufferedReader(reader); String s = null; while((s = br.readLine()) != null) { sb.append(s+'/n'); } br.close(); reader.close(); }catch(Exception e){ e.printStackTrace(); } return sb.toString(); } }