我想刪除使用的FileService存儲文件的淵源存儲的文件。在少數情況下,刪除成功,但大多數情況下不成功,我還沒有找到模式。我在本地服務器上的Windows 7上使用eclipse。我如何刪除文件?在谷歌的AppEngine如何刪除使用的FileService
編輯:當我上傳到AppEngine上它的工作原理。
這裏是存儲代碼:
try
{
FileService fileService = FileServiceFactory.getFileService();
AppEngineFile file = fileService.createNewBlobFile(content_type, fileName);
boolean lock = true;
FileWriteChannel writeChannel = fileService.openWriteChannel(file, lock);
byte[] b1 = new byte[BUFFER_SIZE];
int readBytes1;
while ((readBytes1 = is.read(b1)) != -1)
{
writeChannel.write(ByteBuffer.wrap(b1, 0, readBytes1));
}
writeChannel.closeFinally();
blobKey = fileService.getBlobKey(file);
item_image_blob_key = blobKey.getKeyString();
}
catch (Exception e)
{
System.out.println(e.getLocalizedMessage());
e.printStackTrace(response.getWriter());
}
這裏是刪除嘗試:
@Override
public long deleteItem(Long id)
{
System.out.println(LOG +" Trying to delete item with this id: " + id);
Key parent = KeyFactory.createKey("MffItems", MFF_ITEM_ROOT_KEY);
Key key = KeyFactory.createKey(parent, "Item", id);
try
{
Entity e = datastore.get(key);
String image_key = (String) e.getProperty("image_blob_key");
BlobKey blobKey = new BlobKey(image_key);
final AppEngineFile f = fileService.getBlobFile(blobKey);
if(f.isReadable())
{
System.out.println(LOG + " file is readable");
if(f.hasFinalizedName())
{
System.out.println(LOG + " file has finalized name: " + f.getNamePart());
fileService.delete(f); // Problematic line
datastore.delete(key);
return id;
}
}
}
catch(Exception e)
{
System.out.println(LOG + " " + e.toString() + " " + e.getMessage());
}
// TODO Auto-generated method stub
return -1;
}
這是我得到的錯誤:
I_MFF_ItemService試圖刪除具有此ID的項目:2 I_MFF_ItemService文件可讀 I_MFF_ItemService文件已確定zed name:TXP5bVCmBVugDOxktBGv_w 2013年6月30日12:24:03 PM com.google.appengine.api.blobstore.dev.LocalBlobstoreService $ 1 run 警告:無法刪除blob: java.io.IOException:無法刪除:C :\用戶\基甸\桌面\ dev的\ workspace2 \ ItemManager1.41 \戰爭\ WEB-INF \ AppEngine上生成\ TXP5bVCmBVugDOxktBGv_w 在com.google.appengine.api.blobstore.dev.FileBlobStorage.deleteBlob(FileBlobStorage.java:79 ) at com.google.appengine.api.blobstore.dev.LocalBlobstoreService $ 1.run(LocalBlobstoreService.java:153) at java.security.AccessController.doPrivileged(Native Method) at com.google.appengine.api.blobstore .dev.LocalBlobstoreService.deleteBlob(LocalBlobstoreService.java:146) 在sun.reflect.NativeMethodAccessorImpl.invoke0(本機方法) 在sun.reflect.NativeMethodAccessorImpl.invoke(未知來源) 在sun.reflect.DelegatingMethodAccessorImpl.invoke(未知來源) 在java.lang.reflect.Method.invoke(未知來源) 在com.google.appengine.tools .development.ApiProxyLocalImpl $ AsyncApiCall.callInternal(ApiProxyLocalImpl.java:521) at com.google.appengine.tools.development.ApiProxyLocalImpl $ AsyncApiCall.call(ApiProxyLocalImpl.java:475) at com.google.appengine.tools.development .ApiProxyLocalImpl $ AsyncApiCall.call(ApiProxyLocalImpl.java:452) 在java.util.concurrent.Executors $ PrivilegedCallable $ 1.run(來源不明) 在java.security.AccessController.doPrivileged(本機方法) 在java.util中。 concurrent.Executors $ PrivilegedCallable.call(不明(來源) at java.util.concurrent.FutureTask $ Sync.innerRun(Unknown Source) at java.util.concurrent.FutureTask.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) 在java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(來源不明) 在java.lang.Thread.run(來源不明)
I_MFF_ItemService產生java.io.IOException:Blob存儲故障Blob存儲故障 二零一三年六月三十零日12:24:27 PM com.google.appengine.api.datastore.dev.LocalDatastoreService $ PersistDatastore persist 信息:持續數據存儲的時間:20 ms