How to copy file using FromFile in Struts java
public String copyFile(FormFile formFile, String destinationFolder,
String outputFileName) throws IOException {
byte[] data = new byte[1000];
InputStream input = formFile.getInputStream();
String filename = formFile.getFileName();
new File(destinationFolder).mkdirs();
File file = new File(destinationFolder, outputFileName);
FileOutputStream output = new FileOutputStream(file);
try {
try {
while (true) {
int count = input.read(data);
if (count == -1)
break;
output.write(data, 0, count);
}
} catch (Exception e) {
e.printStackTrace();
}
finally {
input.close();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
output.close();
}
return filename;
}
String outputFileName) throws IOException {
byte[] data = new byte[1000];
InputStream input = formFile.getInputStream();
String filename = formFile.getFileName();
new File(destinationFolder).mkdirs();
File file = new File(destinationFolder, outputFileName);
FileOutputStream output = new FileOutputStream(file);
try {
try {
while (true) {
int count = input.read(data);
if (count == -1)
break;
output.write(data, 0, count);
}
} catch (Exception e) {
e.printStackTrace();
}
finally {
input.close();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
output.close();
}
return filename;
}
Comments
Post a Comment