gpt4 book ai didi

java - 未找到文件异常2

转载 作者:行者123 更新时间:2023-11-30 07:58:18 25 4
gpt4 key购买 nike

String filename = new String(APDirectory.META_DATA.getPath() + getDefaultFileName() + ".ini");
File iniFile = new File(filename);

try {
Wini ini = new Wini(iniFile);
ini.put(title, "Comment:", comment);
ini.put(title, "Position:", rectangle.x + "," + rectangle.y + "," + rectangle.width + "," + rectangle.height);
ini.store();
} catch (InvalidFileFormatException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

static String getDefaultFileName() {
String output = new String(ImageInfo.imageName);

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss");
output += "_" + dateFormat.format(new Date());

return output;
}

我创建了一个新文件,但出现以下错误:

java.io.FileNotFoundException: C:\Users\XXX\AP\MetaData\CB_2015-09-01_07-31-01.ini (Sistem belirtilen dosyayı bulamıyor) at java.io.FileInputStream.open0(Native Method) at java.io.FileInputStream.open(Unknown Source) at java.io.FileInputStream.(Unknown Source)

最佳答案

String filename = new String(APDirectory.META_DATA.getPath() + getDefaultFileName() + ".ini");
System.out.println(APDirectory.META_DATA.getPath() + getDefaultFileName() + ".ini");
File iniFile = new File(filename);

Wini ini;

try {
iniFile.createNewFile();
ini = new Wini(iniFile);
ini.put(title, "Comment:", comment);
ini.put(title, "Position:", rectangle.x + "," + rectangle.y + "," + rectangle.width + "," + rectangle.height);
ini.store();
} catch (InvalidFileFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

我必须使用 iniFile.createNewFile(); 显式创建文件

Wini 构造函数不会自动执行此操作。

关于java - 未找到文件异常2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32326016/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com