FileReader csv:FileNotFoundException:无法将此文件作为文件描述符打开;不能将其作为文件描述符打开.它可能被压缩了 [英] FileReader csv : FileNotFoundException: This file can not be opened as a file descriptor; it is probably compressed
问题描述
我想读取一个csv文件.为此,我找到了像这样使用的CSVReader:
I would like to read a csv file. For that, I found CSVReader which I use like this :
List myEntries = null;
try {
AssetFileDescriptor descriptor = getAssets().openFd("file.csv");
CSVReader csvReader = new CSVReader(new FileReader(descriptor.getFileDescriptor()), ',', '"');
myEntries = csvReader.readAll();
csvReader.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
但是我得到了这个错误: FileNotFoundException:该文件不能作为文件描述符打开;它可能被压缩了.
But I got this error: FileNotFoundException: This file can not be opened as a file descriptor; it is probably compressed.
我的文件位于资产文件夹中.
My file is located in assets folder.
I have already seen this thread: java.io.FileNotFoundException: This file can not be opened as a file descriptor; it is probably compressed It did not help me at all.
所以,我必须做错什么,但是怎么办? 我应该将文件放在另一个文件夹中并通过其他方法打开吗?
So, I must do something wrong, but what? Should I put my file on another folder and open it by another method?
推荐答案
Android压缩所有资产,以下类型除外:
Android compresses all assets, except for the following types:
".jpg", ".jpeg", ".png", ".gif",
".wav", ".mp2", ".mp3", ".ogg", ".aac",
".mpg", ".mpeg", ".mid", ".midi", ".smf", ".jet",
".rtttl", ".imy", ".xmf", ".mp4", ".m4a",
".m4v", ".3gp", ".3gpp", ".3g2", ".3gpp2",
".amr", ".awb", ".wma", ".wmv"
如果您对构建过程有足够的控制权,则可以使用 带有zip或aapt的"-0"标志可添加资产.
If you have sufficient control over the build process, you can use the "-0" flag with zip or aapt to add the assets.
-0指定其他扩展名,此类文件将不会 被压缩存储在.apk中.空字符串表示不 完全压缩任何文件.
-0 specifies an additional extension for which such files will not be stored compressed in the .apk. An empty string means to not compress any files at all.
如果您有机会使用CSVReader进行操作,请将csv文件存放在资产文件夹之外的其他位置,例如sdcard.
If you have the chance to do it with your CSVReader, deposit your csv file somewhere other than the assets folder, like sdcard.
这篇关于FileReader csv:FileNotFoundException:无法将此文件作为文件描述符打开;不能将其作为文件描述符打开.它可能被压缩了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!