标签:path exce new except gen exist ring temp creat
package com.ittx.edi.erp;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
public class test001 {
public static void main(String[] args) {
try {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("你");
while (stringBuilder.toString().getBytes("utf-8").length < 4194304){ //比较字节是否小于4M
System.out.println(stringBuilder.toString().getBytes("utf-8").length);
stringBuilder.append("你你你你你你你");
}
generateNewText("C:\\temp.txt", stringBuilder.toString());
}catch (Exception ex){
}
}
public static File generateNewText(String filePath, String content) {
try {
File file = new File(filePath);
if (!file.exists()) {
file.createNewFile();
}
FileWriter fileWriter = new FileWriter(file);
fileWriter.write(content);
fileWriter.close();
return file;
} catch (Exception ex) {
return null;
}
}
}
标签:path exce new except gen exist ring temp creat
原文地址:https://www.cnblogs.com/joker331/p/12362546.html