我检索了一个" ParseFile"来自" parse.com"。但是,我无法找到一种正确的方法来阅读" ParseFile"我试图用Java" BufferReader"读取parseFile。只是徒劳无功。
下面发布的是我的代码
final ParseQuery<ParseObject> query = ParseQuery.getQuery("TestObject");
query.getInBackground("xxxxxxxxx", new GetCallback<ParseObject>() {
public void done(ParseObject object, ParseException e) {
if (e == null) {
try {
ParseFile parseFile=object.getParseFile("file");
BufferedReader br = new BufferedReader(new FileReader(String.valueOf(parseFile)));
StringBuilder sb = new StringBuilder();
String line = br.readLine();
while (line != null) {
sb.append(line);
sb.append("\n");
line = br.readLine();
}
System.out.println("exact values"+sb.toString());
br.close(); }
catch (Exception e1) {
e1.printStackTrace();
}
} else {
System.out.println("bye!!");
}
}
});
发布的是我的StackTrace:
10-14 00:10:33.178 18300-18300/? W/System.err﹕
java.io.FileNotFoundException:
com.parse.ParseFile@328cdd84: open failed: ENOENT (No such file or
directory)
10-14 00:10:33.178 18300-18300/? W/System.err﹕ at
libcore.io.IoBridge.open(IoBridge.java:409)
10-14 00:10:33.178 18300-18300/? W/System.err﹕ at java.io.FileInputStream.
<init>(FileInputStream.java:78)
10-14 00:10:33.178 18300-18300/? W/System.err﹕ at java.io.FileInputStream.
<init>(FileInputStream.java:105)
10-14 00:10:33.178 18300-18300/? W/System.err﹕ at java.io.FileReader.<init>
(FileReader.java:66)
FilenotFound Exception行指向:
BufferedReader br = new BufferedReader(new FileReader(String.valueOf(parseFile)));
任何建议都会非常有帮助。 谢谢!
答案 0 :(得分:3)
您正在将Object parseFile的字符串传递给FileReader。
更改行
BufferedReader br = new BufferedReader(new FileReader(String.valueOf(parseFile)));
到
BufferedReader br = new BufferedReader(new FileReader(parseFile.getFile()));