너무 궁금한데요


자바로 짠 코드를 이클립스에서 돌리면 디시 게시판 크롤링이 되는데


왜 그대로 가져가서 안드로이드 스튜디오에서 해보면 안될까요? ㅠㅠ


////////////////////이클립스에서 코드////////////////////



public static void main(String[] args) {

  String result = get("http://gall.dcinside.com/mgallery/board/lists/?id=chel","UTF-8");
  System.out.println(result);
 }

 public static String get(String url, String type) {
  BufferedReader in = null;
     String result = "";

     try {

         URL obj = new URL(url);
         HttpURLConnection con = (HttpURLConnection) obj.openConnection();
         con.setRequestMethod("GET");
         in = new BufferedReader(new InputStreamReader(con.getInputStream(), "UTF-8"));
         String line;
         while((line = in.readLine()) != null) {

             result +=line;
         }

     }catch (Exception e) {
         e.printStackTrace();
     }
       finally {
         if(in != null) {
             try {
                 in.close();
             }catch (Exception e) {
                 e.printStackTrace();
             }
         }
     }
    
     return result;
 }


//////////////////////////안드로이드스튜디오에서 코드//////////////////////////




@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);

Button bt = (Button) findViewById(R.id.BT);
textView = (TextView) findViewById(R.id.text);
textView.setMovementMethod(new ScrollingMovementMethod());

bt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

testAsyncTask testAsyncTask = new testAsyncTask();

testAsyncTask.execute();
}
});
}


private class testAsyncTask extends AsyncTask<String, Void, String> {

@Override
protected void onPreExecute() {
super.onPreExecute();
}

@Override
protected String doInBackground(String... params) {

BufferedReader in = null;
String result = "";

try {

URL obj = new URL("https://gall.dcinside.com/mgallery/board/lists/?id=chel");
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("GET");
in = new BufferedReader(new InputStreamReader(con.getInputStream(), "UTF-8"));
String line;
while((line = in.readLine()) != null) {

result +=line;
}

String resul = result;
System.out.println(resul);

}catch (Exception e) {
e.printStackTrace();
}
finally {
if(in != null) {
try {
in.close();
}catch (Exception e) {
e.printStackTrace();
}
}
}