在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML5  Java  Python/ java緩存問題?

java緩存問題?

1.代碼中出現(xiàn)了緩存報錯
2.報錯如下圖

clipboard.png
3.代碼如下:

import java.io.*;
import java.net.*;
public class TEXT{
    
    
    
 public static void main(String[] args) throws IOException {
     
     System.getProperties().setProperty("https.proxyHost", "proxy.tencent.com");
     System.getProperties().setProperty("https.proxyPort", "8080");
  // 定義即將訪問的鏈接
  String url = "https://www.dong12.cn";
  // 定義一個字符串用來存儲網(wǎng)頁內(nèi)容
  String result = "";
  // 定義一個緩沖字符輸入流
  BufferedReader in = null;
  try {
   // 將string轉(zhuǎn)成url對象
   URL realUrl = new URL(url);
   // 初始化一個鏈接到那個url的連接
   URLConnection connection = realUrl.openConnection();
   // 開始實際的連接
   connection.connect();
   // 初始化 BufferedReader輸入流來讀取URL的響應
   in = new BufferedReader(new InputStreamReader(
     connection.getInputStream()));
   // 用來臨時存儲抓取到的每一行的數(shù)據(jù)
   String line;
   while ((line = in.readLine()) != null) {
    //遍歷抓取到的每一行并將其存儲到result里面
    result += line;
   }
  } catch (Exception e) {
   System.out.println("發(fā)送GET請求出現(xiàn)異常!" + e);
   e.printStackTrace();
  }
  // 使用finally來關(guān)閉輸入流
  finally {
   try {
    if (in != null) {
     in.close();
    }
   } catch (Exception e2) {
    e2.printStackTrace();
   }
  }
  

  FileOutputStream fos = new FileOutputStream("E:/poem3.txt") ;
  DataOutputStream dos = new DataOutputStream(fos) ;
  dos.writeUTF(result) ;
  dos.close() ;
  
 }
}


5.我該如何解決?
6.我需要抓取然后寫入到txt文本中
回答
編輯回答
扯不斷

/**
*字節(jié)流下載
*/
public static void getContext(){

    System.getProperties().setProperty("https.proxyHost",
            "proxy.tencent.com");
    System.getProperties().setProperty("https.proxyPort", "8080");
    String url = "https://www.dong12.cn";
    InputStream in=null;
    FileOutputStream os=null;
    try {
        URL realUrl = new URL(url);
        URLConnection connection = realUrl.openConnection();
        connection.connect();
        in = connection.getInputStream();
        os=new FileOutputStream(new File("E:/poem3.html"));
        byte[] b=new byte[1024];
        int c=0;
        while ((c=in.read(b))!=-1) {
            os.write(b,0,c);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }finally {
        try {
            if(os!=null){
                os.close();
            }
            if(in!=null){
                in.close();
            }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
2017年12月25日 10:54