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();
}
}
}
}