2015-10-14 39 views
2

我從「parse.com」中檢索到了「ParseFile」。但是,我無法弄清楚讀取「ParseFile」的正確方法。我嘗試使用parseFile Java的「緩衝區讀取器」只能徒然結束。使用java讀取「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!!"); 
      } 
     } 
    }); 

張貼下面是我的堆棧跟蹤:

10-14 00:10:33.178 18300-18300/? W/System.err﹕  
java.io.FileNotFoundException: 
[email protected]: 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例外指向:

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

任何建議將是非常有益的。 謝謝!

回答

3

您正在將Object parseFile的字符串傳遞給FileReader,而不是File。

更改線路

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

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