I have a file in my assets folder... how do I read it?
Now I'm trying:
public static String readFileAsString(String filePath)
throws java.io.IOException{
StringBuffer fileData = new StringBuffer(1000);
BufferedReader reader = new BufferedReader(
new FileReader(filePath));
char[] buf = new char[1024];
int numRead=0;
while((numRead=reader.read(buf)) != -1){
String readData = String.valueOf(buf, 0, numRead);
fileData.append(readData);
buf = new char[1024];
}
reader.close();
return fileData.toString();
}
But it cast a null pointer exception...
the file is called "origin" and it is in folder assets
I tried to cast it with:
readFileAsString("file:///android_asset/origin");
and
readFileAsString("asset/origin");``
but both failed... any advice?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…