2013-11-15 2 views
0

텍스트 파일에서 데이터를 요청하는 Android 애플리케이션이 있습니다. 데이터 분리 및 클래스 초기화를 시도 할 때 분할 후 데이터의 절반이 누락되어 심각한 문제가 발생합니다. 데이터 소스에 대한 코드는 다음과 같습니다 분할 할 때 분할 할 때 내용을 절반으로 건너 뜁니다. @

indicators = new ArrayList<Indicator>(); 
    try { 
     InputStream fileStream = getResources().openRawResource(
          R.raw.indicators); 
     int fileLen = fileStream.available(); 
     // Read the entire resource into a local byte buffer. 
     byte[] fileBuffer = new byte[fileLen]; 
     fileStream.read(fileBuffer); 
     fileStream.close(); 
     displayText = new String(fileBuffer); 
     String[] counts = displayText.split("@"); 
     for(String i: counts) { 
      String[] temps = i.split(";"); 
      indicators.add(new Indicator(temps[0],temps[1],temps[2])); 
      } 
     } catch (IOException e) { 
      // exception handling 
     } 
    for(Indicator i: indicators) Log.v("indicator", i.toString()); 

및 표시 클래스의 코드

는 여기에서 찾을 수 있습니다 :

public class Indicator { 
    private String name; 
    private String isoCode; 
    private String topic; 

    public Indicator(String topic, String isoCode,String name) { 
     this.name = name; 
     this.isoCode = isoCode; 
     this.topic = topic; 
    } 
    public String getName() { 
     return this.name; 
    } 
    public String getIsoCode() { 
     return this.isoCode; 
    } 
    public String getTopic() { 
     return this.topic; 
    } 
    public String toString() { 
     return (this.topic + "," + this.isoCode + "," + this.name); 
    } 
} 

이 과정을 수행 한 후 다음 로그 파일이없는 많은 콘텐츠와 함께 제공 :

http://pastebin.com/1j5s1Z81

파일은 다른 모든 항목을 건너 뛰는하고, 그 때문에 내 전체 소프트웨어가 엉망 것 같다. 소스 파일은 다음과 같습니다 : 나는 명령을 ammending하여 문제를 해결할 수 없었다

http://pastebin.com/eAzppMdb

+0

호기심에서 "counts"배열의 크기를 파싱하기 전에 어떻게해야합니까? – LokiSinclair

+1

마지막 줄을 제외한 모든 줄의 마지막에'@ '가 있기 때문에'line-by-line'파일을 읽지 않는 이유가 있습니까? 아무튼'System.getProperty ("line.separator")'를 사용하여 새 줄로 나눠보십시오. – Smit

+0

배열 수는 244입니다 ... 표시기를 인쇄 할 때 나는 두 배가됩니다. 이는 어떻게 든 로그가 제대로 작동하지 않거나 기본 소프트웨어가 있음을 의미합니다. –

답변

0

. 그러나이 문제를 해결하기 위해 열린 문자열을 읽는 BufferedReader 클래스를 사용하여 문제를 해결했습니다. 문제가 해결 된 것 같습니다.

관련 문제