package com.heima.test;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class FileOutputTest {
public static void main(String[] args) throws IOException {
File file = new File("C:\\Users\\U000000\\Desktop\\file\\fos.txt");
FileOutputStream fos = new FileOutputStream(file,true);
String s = System.lineSeparator();
byte[] b1 = ("1234"+s).getBytes();
byte[] b2 = "1234\r\n".getBytes();
System.lineSeparator();
fos.write(97);
fos.write(98);
fos.write(121);
fos.write(b2);
fos.close();
}
}
用java删除文件
package com.heima.test;
import java.io.File;
public class DeleteFile {
public static void main(String[] args) {
String dir = "C:\\Users\\U00000\\Desktop\\file\\fos.txt";
boolean success = (new File(dir)).delete();
if (success) {
System.out.println("Successfully deleted empty directory: " + dir);
} else {
System.out.println("Failed to delete empty directory: " + dir);
}
}
}
|