当我从 jar 文件中读取文件并将其放入 jTextArea 时,它会显示加密符号,而不是真实内容。
我在做什么:
public File loadReadme() {
URL url = Main.class.getResource("/readme.txt");
File file = null;
try {
JarURLConnection connection = (JarURLConnection) url
.openConnection();
file = new File(connection.getJarFileURL().toURI());
if (file.exists()) {
this.readme = file;
System.out.println("all ok!");
}
} catch (Exception e) {
System.out.println("not ok");
}
return file;
}
然后我读了文件:
public ArrayList<String> readFileToArray(File file) {
ArrayList<String> array = new ArrayList<String>();
BufferedReader br = null;
try {
String sCurrentLine;
br = new BufferedReader(new FileReader(file));
while ((sCurrentLine = br.readLine()) != null) {
String test = sCurrentLine;
array.add(test);
}
} catch (IOException e) {
System.out.println("not diese!");
} finally {
try {
if (br != null)
br.close();
} catch (IOException ex) {
}
}
return array;
}
现在,我将 ArrayList 中的所有行放在 jTextArea 中,这向我展示了这样的内容:
PK����?����^��S?��3��� z_��
%�Q Tl?7��+�;���fK� �N��:k����� ]�Xk,������U"������q��\����%�Q#4x�|[���o�S{��:�aG�*sg�' .}����x����5��q���hpu�H���W�9���h2��Q����#���@7(�@�� ��F!��~��?����j�?\xA�/�Rr.�v�l�PK�bv�=
文本文件包含:
SELECTION:
----------
By clicking the CTRL Key and the left mouse button you go in the selection mode.
Now, by moving the mouse, you paint a rectangle on the map.
DOWNLOAD:
---------
By clicking on the download button, you start the download.
The default location for the tiles to download is: <your home>
我确定该文件存在!有谁知道问题是什么?我的“getResource”正确吗?