servlet服务端接收:
FileOutputStream fileOutputStream = FileUtils.openOutputStream(new File(resultFile)); InputStream requestInputStream = request.getInputStream(); IOUtils.copy(requestInputStream, fileOutputStream);
客户端上传代码:
URL url = new URL(urlStr); HttpURLConnection httpUrlConnection = (HttpURLConnection) url.openConnection(); httpUrlConnection.setDoOutput(true); httpUrlConnection.setDoInput(true); httpUrlConnection.setUseCaches(false); httpUrlConnection.setRequestMethod("POST"); httpUrlConnection.setRequestProperty("Content-type", "text/html"); httpUrlConnection.setRequestProperty("moduleName", moduleName); httpUrlConnection.setRequestProperty("tdate", tdate); httpUrlConnection.connect(); httpOutputStream = httpUrlConnection.getOutputStream(); IOUtils.copy(inputStream, httpOutputStream);
试了一下,上面这个可以用servlet实现文件传输。
想问一下有没有大神知道,这样的方式,文件传输的量能有多大,原理是什么?