@Test public void testReadFile() throws Exception { String Path = new String("."); Assert.assertNotNull(Utils.readFile(Path)); Path = "./test"; Assert.assertNotNull(Utils.readFile(Path)); Assert.assertTrue(Utils.readFile(Path) == ""); }
protected static String readFile(String Path){ BufferedReader reader = null; String laststr = ""; try{ FileInputStream fileInputStream = new FileInputStream(Path); InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "UTF-8"); reader = new BufferedReader(inputStreamReader); String tempString = null; while((tempString = reader.readLine()) != null){ laststr += tempString; } reader.close(); }catch(IOException e){ log.error("Exception:",e); }finally{ if(reader != null){ try { reader.close(); } catch (IOException e) { log.error("Exception:",e); } } } return laststr; }
Utils { protected static String readFile(String Path){ BufferedReader reader = null; String laststr = ""; try{ FileInputStream fileInputStream = new FileInputStream(Path); InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "UTF-8"); reader = new BufferedReader(inputStreamReader); String tempString = null; while((tempString = reader.readLine()) != null){ laststr += tempString; } reader.close(); }catch(IOException e){ log.error("Exception:",e); }finally{ if(reader != null){ try { reader.close(); } catch (IOException e) { log.error("Exception:",e); } } } return laststr; } }
Utils { protected static String readFile(String Path){ BufferedReader reader = null; String laststr = ""; try{ FileInputStream fileInputStream = new FileInputStream(Path); InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "UTF-8"); reader = new BufferedReader(inputStreamReader); String tempString = null; while((tempString = reader.readLine()) != null){ laststr += tempString; } reader.close(); }catch(IOException e){ log.error("Exception:",e); }finally{ if(reader != null){ try { reader.close(); } catch (IOException e) { log.error("Exception:",e); } } } return laststr; }  }
Utils { protected static String readFile(String Path){ BufferedReader reader = null; String laststr = ""; try{ FileInputStream fileInputStream = new FileInputStream(Path); InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "UTF-8"); reader = new BufferedReader(inputStreamReader); String tempString = null; while((tempString = reader.readLine()) != null){ laststr += tempString; } reader.close(); }catch(IOException e){ log.error("Exception:",e); }finally{ if(reader != null){ try { reader.close(); } catch (IOException e) { log.error("Exception:",e); } } } return laststr; }   }
Utils { protected static String readFile(String Path){ BufferedReader reader = null; String laststr = ""; try{ FileInputStream fileInputStream = new FileInputStream(Path); InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "UTF-8"); reader = new BufferedReader(inputStreamReader); String tempString = null; while((tempString = reader.readLine()) != null){ laststr += tempString; } reader.close(); }catch(IOException e){ log.error("Exception:",e); }finally{ if(reader != null){ try { reader.close(); } catch (IOException e) { log.error("Exception:",e); } } } return laststr; }    }