Posts

Showing posts from March, 2017

convert file to string

public static String readFile(String filePath){ BufferedReader br = null; FileReader fr = null; StringBuilder sb = new StringBuilder(); try { fr = new FileReader(filePath); br = new BufferedReader(fr); String sCurrentLine; br = new BufferedReader(new FileReader(filePath)); while ((sCurrentLine = br.readLine()) != null) { sb.append(sCurrentLine); } } catch (IOException e) { e.printStackTrace(); } finally { try { if (br != null) br.close(); if (fr != null) fr.close(); } catch (IOException ex) { ex.printStackTrace(); } } return sb.toString(); }