HtmlParser 异常 rg.htmlparser.util.ParserException: Exception getting input stream from http:

battier 发布于 2015/01/21 10:21
阅读 888
收藏 0

下载网站图片,在本地环境(MyEclipse8.5)正常,在LINUX上写shell执行就异常,异常信息如下:

org.htmlparser.util.ParserException: Exception getting input stream from http://58.248.187.197/data/stock/mmfx/000001 (http://58.248.187.197/data/stock/mmfx/000001).;
java.io.FileNotFoundException: http://58.248.187.197/data/stock/mmfx/000001
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at sun.net.www.protocol.http.HttpURLConnection$6.run(HttpURLConnection.java:1514)
at java.security.AccessController.doPrivileged(Native Method)
at sun.net.www.protocol.http.HttpURLConnection.getChainedException(HttpURLConnection.java:1508)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1162)
at org.htmlparser.lexer.Page.setConnection(Page.java:571)
at org.htmlparser.lexer.Page.<init>(Page.java:134)
at org.htmlparser.lexer.Lexer.<init>(Lexer.java:186)
at org.htmlparser.Parser.<init>(Parser.java:293)
at org.htmlparser.Parser.<init>(Parser.java:360)
at com.sitech.util.PageParse.getJsonMsg(PageParse.java:68)
at com.sitech.util.PageParse.main(PageParse.java:108)
Caused by: java.io.FileNotFoundException: http://58.248.187.197/data/stock/mmfx/000001
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1457)
at sun.net.www.protocol.http.HttpURLConnection.getHeaderField(HttpURLConnection.java:2340)
at org.htmlparser.lexer.Page.getContentType(Page.java:670)
at org.htmlparser.lexer.Page.setConnection(Page.java:552)
... 6 more
java.net.MalformedURLException
at java.net.URL.<init>(URL.java:601)
at java.net.URL.<init>(URL.java:464)
at java.net.URL.<init>(URL.java:413)
at com.sitech.util.DownloadUtil.download(DownloadUtil.java:64)
at com.sitech.util.PageParse.main(PageParse.java:111)
下载失败
******************************************************

核心代码快:

public boolean download(String url, String code, String moduleName) throws ParserException {
HttpURLConnection hc = null;
InputStream instream = null;
FileOutputStream fos = null;
try {
URL urlobj = new URL(url);
hc = (HttpURLConnection) urlobj.openConnection();
hc.setRequestProperty("User-Agent","Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
// 定义输入流
parser = new Parser(hc);
parser.setEncoding("gb2312");
instream = parser.getConnection().getInputStream();
String tempFileName = getFileNameFromUrl(url, code, moduleName);
String filePathName = createFileDirectory(moduleName, code)
+ tempFileName;
fos = new FileOutputStream(filePathName);
// 定义一个大小为1024的字节数组
byte[] buf = new byte[1024];


// 从输入流中读出字节到定义的字节数组
int len = instream.read(buf, 0, 1024);


// 循环读入字节,然后写到文件输出流中
while (len != -1) {
fos.write(buf, 0, len);
len = instream.read(buf, 0, 1024);
}
fos.flush();
fos.close();
return true;
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}


}
************************************

能否有朋友指点?

加载中
返回顶部
顶部