[英]Large file upload using FileInputStream and FileOutputStream
HttpExchange exchange;
OutputStream responseBody = null;
try{
File fileVal = new File(file);
InputStream inVal = new FileInputStream(fileVal);
exchange.sendResponseHeaders(HTTP_OK, fileVal.length());
responseBody = exchange.getResponseBody();
int read;
byte[] buffer = new byte[4096];
while ((readVal = inVal.read(buffer)) != -1){
responseBody.write(buffer, 0, readVal);
}
} catch (FileNotFoundException e){
//uh-oh, the file doesn't exist
} catch (IOException e){
//uh-oh, there was a problem reading the file or sending the response
} finally {
if (responseBody != null){
responseBody.close();
}
}
我正在嘗試將大視頻文件作為塊上傳。在執行操作時,出現以下錯誤。
groovy.lang.GroovyRuntimeException: Could not find matching constructor for: java.io.File(org.springframework.web.multipart.commons.CommonsMultipartFile)
任何人都指導我解決這個問題。
該錯誤消息完美地描述了故障。 沒有針對File
類的構造函數,該構造函數接受org.springframework.web.multipart.commons.CommonsMultipartFile
類型的參數。
嘗試使用要打開的文件的路徑。 例如:
String path = "/path/to/your/file.txt";
File fileVal = new File(path);
或者,您可以使用CommonsMultipartFile中的getInputStream()
方法。
InputStream inVal = file.getInputStream();
File fileVal = new File(file);
這里的文件是org.springframework.web.multipart.commons.CommonsMultipartFile類型,並且您試圖通過在構造函數中傳遞CommonsMultipartFile對象來創建File對象,並且File類沒有CommonsMultipartFile類型的構造函數。
您需要從文件對象獲取字節並創建一個java.io.File對象。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.