Java 文件 Util

 <textarea cols="50" rows="15" name="code" class="java">import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import com.paic.is.dispatch.TMPEntry; public class FileUtil { public static File getFileByRelativePath(String relativePath) { String absoluteFilePath = ProjectConfig.getApplicationRootPath() + File.separator + relativePath; return new File(absoluteFilePath); } public static String getInjectedFEFileContent(String relativeFilePath, String fileContent) { String FEString = readFEFileContent(relativeFilePath); return fileContent + "/n" + FEString; } public static String readFEFileContent(String relativeFilePath) { String absoluteFilePath = ProjectConfig.getApplicationRootPath() + File.separator + relativeFilePath; File FEFile = new File(absoluteFilePath); StringBuffer sb = new StringBuffer(); if(FEFile.exists() &amp;&amp; FEFile.canRead() &amp;&amp; !FEFile.isDirectory()) { FileReader fr = null; BufferedReader bReader = null; try { fr = new FileReader(FEFile); bReader = new BufferedReader(fr); String line = null; while((line = bReader.readLine()) != null) { sb.append("/n" +line); } } catch(FileNotFoundException ex) { ExceptionDefaultHandler.handle(ex, TMPEntry.getCurrentTMPFileName() + ".log"); } catch(IOException ex) { ExceptionDefaultHandler.handle(ex, TMPEntry.getCurrentTMPFileName() + ".log"); } finally { try { if(null != bReader) { bReader.close(); } if(null != fr) { fr.close(); } } catch(Exception exception) { ExceptionDefaultHandler.handle(exception, TMPEntry.getCurrentTMPFileName() + ".log"); } } } else { ThreadLog.MakeLog("We can not find the file : " +relativeFilePath, TMPEntry.getCurrentTMPFileName() + ".log"); } return sb.toString(); } public static ArrayList&lt;String&gt; getChildrenAbsoluteFilePath(String parentAbsoluteFilePath, String filter) { ArrayList&lt;String&gt; childrenFileAbsoluteFilePath = new ArrayList&lt;String&gt;(); int filterLength = filter.length(); File parentDirectory = new File(parentAbsoluteFilePath); if(parentDirectory.isDirectory()) { File[] childrenFiles = parentDirectory.listFiles(); if(null != childrenFiles &amp;&amp; childrenFiles.length &gt; 0) { for(int i=0; i&lt;childrenFiles.length; i++) { File currentFile = childrenFiles[i]; String currentFileName = currentFile.getName().toLowerCase(); int startIndex = currentFileName.lastIndexOf(filter.toLowerCase()); if(currentFileName.length() - startIndex == filterLength) { childrenFileAbsoluteFilePath.add(currentFile.getAbsolutePath()); } } } } return childrenFileAbsoluteFilePath; } } </textarea> 

你可能感兴趣的:(Java 文件 Util)