开发者

GAE Blob service - how to process uploaded file

My app allows to upload csv file with some data. I want to extract those data and upload them into datastore, but let's assume for this q开发者_如何学Gouestion, that I just want to count lines in text file. What is the best approach to make that task done. Could you give me some code sniplet?

public int countLines(BlobKey key){
  //mising code
}


The BlobstoreInputStream extends InputStream so you can do something like this --

public int countLines(BlobKey key) throws Exception {
          BlobstoreInputStream bsis = new BlobstoreInputStream(key);
          BufferedReader br = new BufferedReader(new InputStreamReader(bsis));

          int lineCount = 0;
          while ( br.readLine() != null ) 
                 lineCount++;

          return lineCount;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜