Here you can find the source of readTextFile(String fileName)
Parameter | Description |
---|---|
fileName | file name specified |
public static String readTextFile(String fileName)
import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.OutputStreamWriter; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; public class Main{ public static final String tmpdir = System .getProperty("java.io.tmpdir") + File.separator; /**/*from w ww . ja v a2s.c o m*/ * read text from a specified text file store in temporary path * @param fileName file name specified * @return text file content */ public static String readTextFile(String fileName) { try { File file = new File(FileUtil.tmpdir + fileName + ".txt"); FileReader reader = new FileReader(file); BufferedReader in = new BufferedReader(reader); String line; StringBuffer sb = new StringBuffer(); while ((line = in.readLine()) != null) { sb.append(line); } in.close(); return sb.toString(); } catch (IOException e) { throw new RuntimeException(e); } } }