나는 빠른 읽기 txt 파일을 ArrayList에 문제가 있습니다. 파일 크기를 0,9MB로 읽으려면 5 분을 기다려야합니다. 파일 크기가 34MB이면 (안드로이드가 1MB보다 큰 파일을 허용하지 않기 때문에 부분적입니다.) 완전히 작동하지 않습니다. 프로세스가 최대 몇 초가되어야한다고 생각합니다.어떻게 빨리 안드로이드에 ArrayList에 텍스트 파일을 읽을 수
String word;
public ArrayList<String> dictionary = new ArrayList<String>();
public void setup()
{
try {
AssetManager assetManager = getAssets();
InputStream inputf;
inputf = assetManager.open("dict_1.txt");
reader = new BufferedReader(new InputStreamReader(inputf));
word = " ";
while(word != null)
{
word = reader.readLine();
if (word != null)
dictionary.add(word);
}
if(reader.equals("null")) println("No file found");
} catch (NullPointerException e) {
e.printStackTrace();
println("No file found");
} catch (IOException e) {
e.printStackTrace();
}
}
내 영어에 대한 미안 해요 :
이
는 코드입니다. 나는 모두가 understadable이기를 바랍니다.
시작 효율성
o(1)
을 제공 .IT 대신arraylist
의linkedlist
를 사용해야합니다 잖습니까. – CommonsWare'reader'는 "null"과 같을 수없고 NullPointerException은 본질적으로 '파일을 찾을 수 없음'을 의미하지 않습니다. 이상한 오류 및 예외 처리 문제를 수정하는 것이 좋습니다. – EJP
예외 처리 문제를 해결했지만 너무 느리지 만 파일을 완전히 읽으면 중요하지 않습니다. – TheDealer105