67,513
社区成员
发帖
与我相关
我的任务
分享
public String receive(DataHandler handler, String fileName) {
File file = new File(fileName);
if (handler == null || fileName == null || "".equals(fileName)) {
return "errors";
}
InputStream input = null;
FileOutputStream fos = null;
try {
input = handler.getInputStream();
fos = new FileOutputStream(file);
byte[] buffer = new byte[1024];
while (input.read(buffer) != -1) {
fos.write(buffer);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
System.out.println(file.getAbsolutePath());
return "Success file saved on server, at: " + file.getAbsolutePath();
}