0

I am trying to do what FileWriter.println() and BufferedReader.readLine() do in Android, but in android they only allow writing it into the sdcard using those method.

I need to write some integer values into the file and then read it line by line at a later time. Some of the file operation methods I found require the length of the data read to be specified, which is not possible.

Can anyone point me to the right method? Preferably with an example of the usage...

Regards

4

1 に答える 1

0

このパス「\sdcard\file_name」を使用して、SD カードに書き込むことができます。

そしてこう読むと、

 InputStream instream = null;

    as

  InputStream instream = openFileInput("/sdcard/filename");

    // if file the available for reading
    if (instream != null) {
      // prepare the file for reading
      InputStreamReader inputreader = new InputStreamReader(instream);
      BufferedReader buffreader = new BufferedReader(inputreader);

      String line;

      // read every line of the file into the line-variable, on line at the time
      try {
        while (( line = buffreader.readLine()) != null) {
           Log.i(TAG, "line = "+line);
          }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    }

    // close the file again
    try {
        instream.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
于 2011-06-29T20:30:24.723 に答える