![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
Code
/**
* @author
* @date 2008.9.13
* @version 1.0
*/
import java.io.*;
/**
* Class that has commonly used functions
*
* @author
*
*/
public class Utility {
/**
* Static method to write a file
*
* @param filePath
* @param fileContent
* @throws Exception
*/
public static void writeFile(String filePath, String fileContent)
throws IOException {
File folder = (new File(filePath)).getParentFile();
if (!folder.exists()) {
folder.mkdirs();
}
FileWriter fw = new FileWriter(filePath);
BufferedWriter bw = new BufferedWriter(fw);
bw.write(fileContent);
bw.close();
fw.close();
}
/**
* Static method to read a file
*
* @param filePath
* @return fileContent
* @throws Exception
*/
public static String readFile(String filePath) throws IOException {
FileReader fr = new FileReader(filePath);
BufferedReader br = new BufferedReader(fr);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = br.readLine()) != null) {
sb.append(line);
}
br.close();
fr.close();
return sb.toString();
}
}
posted @
2008-09-23 12:47
N/A2011
阅读(
190)
评论()
编辑
收藏
举报