gpt4 book ai didi

Java - 处理 Windows 7 中的库(例如文档、图片等)

转载 作者:行者123 更新时间:2023-12-01 05:18:49 24 4
gpt4 key购买 nike

Windows 对待库的方式不同于常规文件夹和路径。因此,当我使用此代码块创建文本文件时:

File filePath = fc.getSelectedFile();

...更多不相关的东西...

File outputText = new File(filePath.getParentFile(), "Decrypted.txt");

try
{
FileWriter fw = new FileWriter(outputText); //Write everything to the file.
fw.write(messageOut);
fw.close(); //DON'T FORGET TO CLOSE THE FILE!
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}

如果文件位于桌面文件夹中,它就可以工作,但如果我尝试将其放入“我的图片库”中,则会收到以下错误消息:

java.io.FileNotFoundException: ::{031E4825-7B94-4DC3-B131-E946B44C8DD5}\Pictures.library-ms\Decrypted.txt (The system cannot find the path specified)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileWriter.<init>(Unknown Source)
at code.Crypto.decrypt(Crypto.java:57)
at code.Crypto.main(Crypto.java:27)

有办法解决这个问题吗?

最佳答案

看起来像一个错误,在我的系统以及 java 7 update4 32 位上进行了测试和确认。

JFileChooser fc = new JFileChooser();
int returnVal = fc.showSaveDialog(null);
//select and enter a name for a file under libraries (with windows look and feel
//select 'desktop' in the left pane, then libraries->pictures)
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
FileWriter fw = new FileWriter(file); //<-- FileNotFoundException
fw.write("foo bar");
fw.close();
}

异常:

Exception in thread "main" java.io.FileNotFoundException: ::{031E4825-7B94-4DC3-B131-E946B44C8DD5}\Pictures.library-ms\hej.txt (The system cannot find the path specified)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:212)
at java.io.FileOutputStream.<init>(FileOutputStream.java:165)
at java.io.FileWriter.<init>(FileWriter.java:90)
at test.Main.main(Main.java:16)

一个丑陋的解决方法可能是指定一个文件过滤器来过滤掉这些文件,请参阅:

Selecting 'Computer' or 'Libraries' in Java's JFileChooser yields a strange File object

关于Java - 处理 Windows 7 中的库(例如文档、图片等),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10777647/

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