gpt4 book ai didi

java - 使用 java 读取 "ParseFile"

转载 作者:搜寻专家 更新时间:2023-11-01 08:40:28 26 4
gpt4 key购买 nike

我已经从“parse.com”中检索到一个“ParseFile”。但是,我无法找到读取该“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)));

任何建议都会非常有帮助。谢谢!

最佳答案

您正在将对象 parseFile 的字符串而不是文件传递给 FileReader。

换行

    BufferedReader br = new BufferedReader(new FileReader(String.valueOf(parseFile)));

BufferedReader br = new BufferedReader(new FileReader(parseFile.getFile()));

关于java - 使用 java 读取 "ParseFile",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33116665/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com