Java 将字符串换行不覆盖写入txt文件
2014-11-18 11:53
756 查看
Java的一些小常识应用
/**
* 讲字符串换行覆盖写入txt
* @param string
*/
public static void writeTxt(String string){
byte[] buff = new byte[] {};
FileOutputStream fos = null;
String filePath = "C:\\微博URL.txt";
String str = string+System.getProperty("line.separator");
File file = new File(filePath);
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
try {
buff = str.getBytes();
fos = new FileOutputStream(file, true);
fos.write(buff);
} catch (FileNotFoundException e1) {
e1.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
/**
* 讲字符串换行覆盖写入txt
* @param string
*/
public static void writeTxt(String string){
byte[] buff = new byte[] {};
FileOutputStream fos = null;
String filePath = "C:\\微博URL.txt";
String str = string+System.getProperty("line.separator");
File file = new File(filePath);
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
try {
buff = str.getBytes();
fos = new FileOutputStream(file, true);
fos.write(buff);
} catch (FileNotFoundException e1) {
e1.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
相关文章推荐
- java 流将字符串保存到.txt文件中并换行
- java的io操作(将字符串写入到txt文件中)
- java的io操作(将字符串写入到txt文件中)
- java将字符串写入到txt文件中
- java的io操作(将字符串写入到txt文件中)
- java的io操作(将字符串写入到txt文件中)
- java字符串写入文件及换行问题
- Java学习笔记1:将字符串写入txt文件中
- java向txt文件中写入数据时换行
- java文件输出流,写到.txt文件,如何实现换行
- java实现持续写入内容到txt文件
- PHP 写入txt文件换行
- java文件输出流,写到.txt文件,实现换行
- 1000条数据写入到txt文件中,并且做了换行
- JAVA 创建TXT文件,写入文件内容,读取文件内容
- java文件写入怎样换行
- 将字符串写入txt文件的指定位置
- java将数据写入到txt文件中(txt有固定的格式)
- java 流 写入txt文件, 并且设置txt编码格式
- php fwrite写入txt文件的时候用 \r\n不能换行