我尝试使用实验性的Writing Files to Blobstore,即使使用了演示代码,在尝试读取文件时也始终收到FinalizationException。

我使用的代码如下:

FileService fileService = FileServiceFactory.getFileService();

AppEngineFile file = null;
file = fileService.createNewBlobFile("text/plain");

FileWriteChannel writeChannel = fileService.openWriteChannel(file, true);

PrintWriter out = new PrintWriter(Channels.newWriter(writeChannel, "UTF8"));
out.println("The woods are lovely dark and deep.");
out.println("But I have promises to keep.");

out.close();
String path = file.getFullPath();

file = new AppEngineFile(path);

writeChannel = fileService.openWriteChannel(file, true);

writeChannel.write(ByteBuffer.wrap("And miles to go before I sleep.".getBytes()));

writeChannel.closeFinally();


我在另一个请求中获得FinalizationException的读取代码如下:

    FileService fileService = FileServiceFactory.getFileService();

    String path = //get the path code
    AppEngineFile file = new AppEngineFile(path);

    FileReadChannel readChannel;
    try {
        readChannel = fileService.openReadChannel(file, false);
    } catch (FileNotFoundException e) { }


我在openReadChannel行收到了Finalization Exception

任何帮助,将不胜感激。

最佳答案

该示例在开发服务器上运行良好。

09-13 06:17