FileInputStream始终无法读取文件

时间:2016-02-18 11:49:35

标签: android-studio directory fileinputstream

我尝试使用.raw从Android外部存储目录中读取FileInputStream音频文件。有时,我可以读取文件,有时不读。这种情况的原因是什么?

任何帮助将不胜感激。

storageDir = Environment.getExternalStorageDirectory().getAbsolutePath();
enrollWavPath = storageDir + 1 + ".raw";

File file = new File(enrollRawPath);
byte[] byteData = null;
int size = (int) file.length();
byteData = new byte[(int)(size)];
FileInputStream iFileStream = new FileInputStream(file);

int bytesread = 0;
int ret = 0;
while (bytesread < size) {
    ret = iFileStream.read( byteData,0, 2*count);
    if (ret != -1) {
        shortData = byte2short(byteData);
        bytesread += ret;
    }
    else {
        break;
    }
}

iFileStream.close();

0 个答案:

没有答案