/**
* @author a
* @see 写文件
* @param String fileContent
* @param String filePath
* @param int type
* type 1 :使用FileWriter的方式
* 2:使用FileOutputStream
* 3:BufferedOutputStream
* */
private void writeFile(String fileContent,String filePath,int type) {
FileWriter fw = null;
FileOutputStream out = null;
FileOutputStream outSTr = null;
BufferedOutputStream Buff=null;
switch (type) {
case 1:
try {
fw = new FileWriter(filePath);//"C:/add2.txt"
fw.write(fileContent);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
fw.close();
} catch (Exception e) {
e.printStackTrace();
}
}
break;
case 2:
try {
outSTr = new FileOutputStream(new File(filePath));
Buff=new BufferedOutputStream(outSTr);
Buff.write(fileContent.getBytes());
Buff.flush();
Buff.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
outSTr.close();
} catch (Exception e) {
e.printStackTrace();
}
}
case 3:
try {
out = new FileOutputStream(new File(filePath));
out.write(fileContent.getBytes());
out.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
default:
break;
}
}
|