File file1 = null;
if (!file.isFile()) {
file1 = new File("E:\\a\\aa\\b\\test.txt");
boolean createNewFile = false;
try {
createNewFile = file1.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(createNewFile);
}
String str = "这些都将写入文件中";
byte[] bb = str.getBytes(); // 将字符串转换成字节数
OutputStream out = null;
try {
out = new FileOutputStream(file1); // 实例化OutpurStream
} catch (FileNotFoundException e) {
e.printStackTrace();
}
// 写入
try {
out.write(bb); // 写入
out.close(); // 关闭
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("----------------------------------------");
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交