-1

.txt ファイルから Android の ReaderClass にデータを読み込みたいのですが、フィールドは「;」で区切られています。

----これが私の最後の投稿の私の解決策です:

public void cut()
  {
  try{    


  InputStream input =context.getResources().openRawResource(R.raw.textfile);
  BufferedReader br = null;
  br=new BufferedReader(new InputStreamReader(input,"iso-8859-1"));
  String line = null; 


  while ((line = br.readLine()) != null)   {        

      String[] decoupage= line.split(";");


      String titre=decoupage[0];
      String description=decoupage[1];
      String reponse=decoupage[2];
      String explication=decoupage[3];
      String categorie=decoupage[4];
      String etat=decoupage[5];       

                    //test Logcat

            Log.d("information ", " buffer");
        Log.i("titre : ",titre);
        Log.i("description : ",description);
        Log.i("reponse : ",reponse);
        Log.i("explication : ",explication);
        Log.i("categorie : ",categorie);
        Log.i("etat : ",etat);



      }
  in.close();

    }catch (Exception e){
  System.err.println("Error: " + e.getMessage());
  System.err.println("\n File not found");
  }
  //end
  }
4

1 に答える 1

1
FileInputStream fis;
fis = openFileInput("sample.txt");
StringBuffer Content = new StringBuffer("");

byte[] buffer = new byte[1024];
int length;
while ((length = fis.read(buffer)) != -1) {
    Content.append(new String(buffer));
}

you will get entire content in a string buffer ,convert it into string, then you can apply yourString.split(";") to get all values which you can keep in some array.
于 2012-07-17T11:47:53.143 に答える