当输入的字符为“é”(ALT130)时,我在读取URL的JSON时遇到问题。奇怪的是,程序在从NetBeans IDE中启动时可以正常工作,但是从分发jar启动时不会。这是我正在使用的代码:
public class URLReader {
private URL url;
private BufferedReader in;
private String inputLine;
public void getTextFromURL(String address) {
try {
url = new URL(address);
GUI.textArea.append("url created\n");
in = new BufferedReader(new InputStreamReader(url.openStream(),"UTF-8"));
GUI.textArea.append("buffered reader created\n");
while((inputLine = in.readLine()) != null)
GUI.textArea.append(inputLine+"\n");
in.close();
} catch (IOException ex) {
GUI.textArea.append("IO Exception");
}
}
从NetBeans IDE中启动程序时获得的输出如下:
然而,当我从dist jar启动程序时,我得到的输出是:
似乎可以很好地创建URL对象,但BufferedReader似乎抛出了IOException。可能有什么不对?