我有这个当前代码。该文件位于InputStream in
或test.pdf
上的内存中。我希望只保留在内存中。
FileOutputStream fos = new FileOutputStream(new File("test.pdf"));
// Read file
InputStream in = url.openStream();
while((bufferLength = in.read(buffer)) != -1) {
fos.write(buffer, 0, bufferLength);
}
fos.flush();
// Close connections
fos.close();
in.close();
System.out.println("GOT DOCUMENT");
String submitURl = "https://someURL/submit";
// Send data
HttpURLConnection conn = (HttpURLConnection) new URL(submitURl).openConnection();
conn.setRequestMethod("POST");
conn.setDoOutput(true);
conn.setUseCaches(false);
conn.setRequestProperty("Content-Type","multipart/form-data");
conn.setRequestProperty("User-Agent", "Test Agent");
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.flush();
如何将此文件发布到/submit
URL。我在这里想念什么?