我寫了成功上傳的斑點一個servlet,但它是一個沒有名字上傳如何在servlet在GAE/J的FileService API設置文件名
在這裏設置上傳文件的名稱是servlet的段代碼
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
FileService fileService = FileServiceFactory.getFileService();
// Create a new Blob file with mime-type "text/plain"
String url="http://www.cbwe.gov.in/htmleditor1/pdf/sample.pdf";
URL url1=new URL(url);
HttpURLConnection conn=(HttpURLConnection) url1.openConnection();
String content_type=conn.getContentType();
InputStream stream =conn.getInputStream();
AppEngineFile file = fileService.createNewBlobFile("application/pdf");
file=new AppEngineFile(file.getFullPath());
Boolean lock = true;
FileWriteChannel writeChannel = fileService.openWriteChannel(file, lock);
// This time we write to the channel directly
String s1="";
String s2="";
byte[] bytes = IOUtils.toByteArray(stream);
writeChannel.write(ByteBuffer.wrap(bytes));
writeChannel.closeFinally();
'openWriteChannel(..)'不採取三個參數。 – 2012-08-11 11:07:40