Speichern der Datei im Ressourcenverzeichnis mit Spring

Ich habe diese Projektstruktur:


/webapp
  /res
    /img
      /profile.jpg
  /WEB-INF

Und ich muss die Datei speichernres/img/ Verzeichnis. Diesmal habe ich diesen Code:


public String fileUpload(UploadedFile uploadedFile) {
        InputStream inputStream = null;
        OutputStream outputStream = null;
        MultipartFile file = uploadedFile.getFile();
        String fileName = file.getOriginalFilename();
        File newFile = new File("/res/img/" + fileName);

        try {
            inputStream = file.getInputStream();

            if (!newFile.exists()) {
                newFile.createNewFile();
            }
            outputStream = new FileOutputStream(newFile);
            int read = 0;
            byte[] bytes = new byte[1024];

            while ((read = inputStream.read(bytes)) != -1) {
                outputStream.write(bytes, 0, read);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

        return newFile.getAbsolutePath();
    }

Aber es speichert Dateienuser.dir Verzeichnis, das ist~/Work/Tomcat/bin/. Also, wie kann ich Dateien hochladenres Verzeichnis?

Antworten auf die Frage(2)

Ihre Antwort auf die Frage