2017-10-26 5 views
0

HTTPを使用してファイルをダウンロードしようとしていますが、ここにコードがあります。
これで正しい名前でディレクトリが作成され、正しい名前でディレクトリ内のファイルが作成されましたが、ファイルには何も書き込まれません。HTTP POSTメソッドを使用して空のファイルを受信しました

PostMethod post = new PostMethod(serverUrl); 
post.setRequestEntity(entity); 
httpclient.executeMethod(post); 

File contentDirectory = new File(fileFullPath); 
if(contentDirectory.exists() == false){ 
    contentDirectory.mkdir(); 
} 

File localFile = new File(fileFullPath + File.separator + filename); 

int readBuf = 0; 
byte[] buf = new byte[Utils.getBufferSize()]; (BufferSize Checked) 
InputStream is = null; 

is = post.getResponseBodyAsStream(); 
FileOutputStream fos = new FileOutputStream(localFile); 

while((readBuf = is.read(buf))!= -1){ 
    fos.write(buf, 0, readBuf); 
    logger.info("readBuf : "+readBuf); 
} 

is.close(); 
fos.close();enter code here 

if(localFile.exists()) Transfer_Success = true; 

答えて

0

私はnoobですので、今回はすべて間違ったサーブレットにpostメソッドを送信していました。初心者だけの間違い。

私は正しくバイトを転送しましたが、今回は間違ったエンコーディングタイプなどでイメージファイルを開くことができません。私はこれを解決するつもりです。

関連する問題