簡單的-寫入txt文本,追加寫入與覆蓋寫入
/**
*
* Description:追加的寫入
* @param pathName
* @param content
* @author diaowj:2016-4-21
*/
public static void writeFile(String pathName,String content){
File file = new File(pathName);
if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs();
}
try {
FileWriter writer;
writer = new FileWriter(pathName, true);
writer.write(content);
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
/**
*
* Description:覆蓋的寫入
* @param pathName
* @param content
* @author diaowj:2016-4-21
*/
public static void writeDetailFile(String pathName,String content){
try {
File file = new File(pathName);
if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs();
}
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"));
writer.write(content);
writer.close();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
*
* Description:追加的寫入
* @param pathName
* @param content
* @author diaowj:2016-4-21
*/
public static void writeFile(String pathName,String content){
File file = new File(pathName);
if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs();
}
try {
FileWriter writer;
writer = new FileWriter(pathName, true);
writer.write(content);
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
/**
*
* Description:覆蓋的寫入
* @param pathName
* @param content
* @author diaowj:2016-4-21
*/
public static void writeDetailFile(String pathName,String content){
try {
File file = new File(pathName);
if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs();
}
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"));
writer.write(content);
writer.close();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.