1

txt ファイルから float 値を読み取ろうとしていますが、常に値 0 を取得します。writeFloat() を使用してファイルに値を書き込み、readFloat() を使用して読み取ります。コンピューター (Matlab など) で読み取ると正しい値が得られますが、コードを読み取ると、読み取り値として 0 が得られます。コードの何が問題になっていますか?

WRITE_EXTERNAL_STORAGE および READ_EXTERNAL_STORAGE 権限を追加しましたが、ファイルのパスは正しいです。

値を書き込む

try{
    DataOutputStream dos = new DataOutputStream( new FileOutputStream(filename,true));
    for (int i=0; i<100; i++)
        dos.writeFloat(value[i]);
    dos.close();
  }
catch(Exception e){;}

読み取り値

String strFilePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/MyApp/Values.txt";


try
{
  FileInputStream fin = new FileInputStream(strFilePath:);

   DataInputStream dis = new DataInputStream(fin);

    float f;
    for (int i=0; i<100; i++) {
        f = dis.readFloat();
        Log.d("TAG", "float " + Float.toString(f));
    }

     dis.close();
   }
catch(FileNotFoundException fe)
{
  Log.d("ERROR", "FileNotFoundException : " + fe);
}
catch(IOException ioe)
{
  Log.d("ERROR","IOException : " + ioe);
}
4

0 に答える 0