I am trying to get the basics of I/O with Spring.
I am working through the File Upload samples. I want to store the files in a temporary folder in the project for testing.
I have this code:
@RequestMapping(value="/upload", method=RequestMethod.POST)
public @ResponseBody String handleFileUpload(@RequestParam("name") String name,
@RequestParam("file") MultipartFile file){
if (!file.isEmpty()) {
try {
byte[] bytes = file.getBytes();
BufferedOutputStream stream =
new BufferedOutputStream(new FileOutputStream(new File(name)));
//get directory
stream.write(bytes);
stream.close();
I have created folder "files"
within the project files. I want to know how to target the local folder.
I have tried using class File
's alternate constructor.
Aucun commentaire:
Enregistrer un commentaire