Continent.txt
파일이 내 res/raw 폴더에 있습니다. 안에는 다음 내용이 들어 있습니다.Jsoup를 사용하여 텍스트 파일 구문 분석
<div class="continents">
<a href="#US">US</a>
<a href="#CA">Canada</a>
<a href="#EU">Europe</a>
</div>
나는 미국, 캐나다, 유럽이 jsoup 사용하여 텍스트 을 구문 분석 할 수 있어요,하지만 난 텍스트 뷰에 표시 할 때, 그들은 한 줄에 표시됩니다. 결과는 다음과 같습니다.
미국 캐나다 유럽
은 내가 OUPUT이처럼되고 싶어요.
미국
캐나다
유럽
이 내 코드입니다.
package com.example.readfile;
import java.io.InputStream;
import java.util.ArrayList;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.content.res.Resources;
import android.widget.TextView;
public class MainActivity extends Activity {
TextView txtContinent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtContinent = (TextView) findViewById(R.id.textView1);
new MyTask().execute();
}
class MyTask extends AsyncTask<Void, Void, ArrayList<String>> {
ArrayList<String> arr_linkText = new ArrayList<String>();
@Override
protected ArrayList<String> doInBackground(Void... params) {
Document doc;
try {
Resources res = getResources();
InputStream in_s = res.openRawResource(R.raw.continent);
byte[] b = new byte[in_s.available()];
in_s.read(b);
doc = Jsoup.parse(new String(b));
Element link = doc.select("a").first();
String text = doc.body().text();
arr_linkText.add(text);
} catch (Exception e) {
// e.printStackTrace();
txtContinent.setText("Error: can't open file.");
}
return arr_linkText; // << retrun ArrayList from here
}
@Override
protected void onPostExecute(ArrayList<String> result) {
for (String temp_result : result) {
txtContinent.append(temp_result + "\n");
}
}
}
}
줄 단위로 파일을 읽는 방법을 모르겠지만 다른 사람이 나에게 설명해주기를 바랍니다. 고맙습니다!
당신은 보스입니다. 도와 주셔서 감사합니다! – Questions