diff options
author | Huabing Zhao <zhaohuabing@gmail.com> | 2018-08-02 01:28:34 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-08-02 01:28:34 +0000 |
commit | cf6d7a3a83035a22207bc0fea03b59b3b7ebfb5d (patch) | |
tree | f42fb0cad07f527ecfdd7f47c0e2c160571bc916 /apiroute | |
parent | 2f305bed728c56aea6ac684457ff1d08007b8b90 (diff) | |
parent | 5f8754c15602233b09b3bf202b545ee9ad26a251 (diff) |
Merge "try with resorces"
Diffstat (limited to 'apiroute')
-rw-r--r-- | apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/util/FileUtil.java | 21 |
1 files changed, 4 insertions, 17 deletions
diff --git a/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/util/FileUtil.java b/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/util/FileUtil.java index 2b6468b..234bf51 100644 --- a/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/util/FileUtil.java +++ b/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/util/FileUtil.java @@ -25,7 +25,7 @@ public final class FileUtil { /** * Read all the files under a folder */ - public static File[] readFileFolder(String filepath) throws FileNotFoundException, IOException { + public static File[] readFileFolder(String filepath) throws IOException { File file = new File(filepath); if (file.isDirectory()) { File[] filelist = file.listFiles(); @@ -36,28 +36,15 @@ public final class FileUtil { } public static String readFile(String Path) throws IOException { - BufferedReader reader = null; - StringBuffer fileContent = new StringBuffer(); - try { - FileInputStream fileInputStream = new FileInputStream(Path); - InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "UTF-8"); - reader = new BufferedReader(inputStreamReader); + StringBuilder fileContent = new StringBuilder(); + try(BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(Path),"UTF-8"));) { String tempString = null; while ((tempString = reader.readLine()) != null) { fileContent.append(tempString); } - reader.close(); } catch (IOException e) { throw e; - } finally { - if (reader != null) { - try { - reader.close(); - } catch (IOException e) { - throw e; - } - } - } + } return fileContent.toString(); } |