下面的代码我在本机(win7)能成功运行,但是在Linux服务器上运行报错: import java.io.BufferedReader; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; public class TestMail { public static void main(String[] args) { StringBuffer document = new StringBuffer(); try { URL url = new URL("http://localhost:8111/test/jsp/index.jsp?user_id=1052&cycle=0"); URLConnection conn = url.openConnection(); InputStream is = conn.getInputStream(); InputStreamReader isr =new InputStreamReader(is,"UTF-8"); BufferedReader reader = new BufferedReader(isr); String line = null; while ((line = reader.readLine()) != null) document.append(line + "\r\n"); reader.close(); isr.close(); is.close(); writerFile("/home", "test112.html", document.toString()); System.out.println(conn); System.out.println("测试url.openConnection!"); } catch (MalformedURLException e) { // TODO Auto-generated catch block System.out.println("111"); e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block System.out.println("222"); e.printStackTrace(); } } public static int writerFile(String path, String fileName, String content) { String pathFileName = path + File.separator + fileName; File fpath = new File(path); int ok = 0; try { if (!fpath.exists()) { fpath.mkdirs(); } FileOutputStream fileOutputStream = new FileOutputStream( pathFileName); OutputStreamWriter outputStreamWriter = new OutputStreamWriter( fileOutputStream, "utf-8"); outputStreamWriter.write(content.toString()); outputStreamWriter.close(); fileOutputStream.close(); } catch (Exception e) { e.printStackTrace(); } finally { } return ok; } } 报错信息: 各路大神请帮忙啊,感谢! |
|
10分 |
你这句 ?user_id=1052&cycle=0 是要进行数据库的数据的查询吗??
|
10分 |
|
10分 |
unix 上 没有http://localhost:8111 打开“?
|
10分 |
你跳转了一个jsp 然后读取jsp 返回的源码?
|