Skip to content
This repository has been archived by the owner on Jan 12, 2022. It is now read-only.

Latest commit

 

History

History
23 lines (17 loc) · 725 Bytes

StringUtils.md

File metadata and controls

23 lines (17 loc) · 725 Bytes

StringUtils do Spring Framework

Método cleanPath

  • Reajusta os separadores do Windows, ou seja, substitui "" por "/"

  • Exemplo retirado do projeto spring-boot-multipart-sample

    public String storeFile(MultipartFile file) {
        String cleanedFileName = StringUtils.cleanPath(file.getOriginalFilename());
        Path filePath = Paths.get(fileStoragePath + "\\" + cleanedFileName);
    
        try {
            Files.copy(file.getInputStream(), filePath, StandardCopyOption.REPLACE_EXISTING);
        } catch (IOException e) {
            log.error(e);
            throw new RuntimeException("Ocorreu um erro ao copiar o arquivo para o diretório.", e.getCause());
        }
    
        return cleanedFileName;
    }