/*
* 写入文件
*/
public static void writeFile(String data, String filePath) throws Exception {
OutputStream out = null;
InputStream is = null;
File f = new File(filePath);
if (!f.exists()) {
f.mkdirs();
}
byte[] bs = data.getBytes();
out = new FileOutputStream(filePath);
is = new ByteArrayInputStream(bs);
byte[] buff = new byte[1024];
int len = 0;
while ((len = is.read(buff)) != -1) {
out.write(buff, 0, len);
}
is.close();
out.close();
}
/*
* 读取文件
*/
public static StringBuffer readFile(String filePath) throws Exception {
StringBuffer sb = new StringBuffer();
File f = new File(filePath);
FileInputStream is = new FileInputStream(f);
byte[] buff = new byte[1024];
int len = 0;
while ((len = is.read(buff)) != -1) {
sb.append(new String(buff, 0, len));
}
is.close();
return sb;
}