當我從jar文件中讀取一個文件並想將它放入一個jTextArea中時,它會顯示加密的符號,而不是真正的內容。Main.class.getResource()和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;
}
現在,我把所有的線從JTextArea中ArrayList中,這showes我這樣的事情:
PK 2 -S 3 Z_
%Q鉈7+;?? FK N :k ] Xk, U「 q \ % Q#4x | [ o S { :AG * SG」} nX5qhpuHW9h2Q# @ 7( @ F! 〜 j ?\xA/rr v l PK bv =
textfiled包含:
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」是否正確?
readme.txt包含什麼內容?換句話說,你期望的輸出是什麼? – BackSlash 2013-03-27 09:37:01
用此更新您的問題,我認爲可能有用 – BackSlash 2013-03-27 09:42:54
做到了!對不起,我是初學者;) – 2013-03-27 09:43:56