InvalidPathException: Malformed input or input contains unma

时间:2022-06-27 05:35:30

一、 hutools 依赖 centos7

<dependency>
    <groupId>cn.hutool</groupId>
    <artifactId>hutool-all</artifactId>
    <version>4.5.7</version>
</dependency>


FileUtil.copy(srcfilename, destfilename, true);

报错:
Caused by: java.nio.file.InvalidPathException: Malformed input or input contains unmappable characters: 
/home/face/facewatchertemps/images/???_495182728904310784_.jpg

二、测试替换方案;新项目
public class EncodeTest {
public static void main(String[] args) {
System.out.println("sun.jnu.encoding >>>" System.getProperty("sun.jnu.encoding"));
System.out.println("file.encoding >>>" System.getProperty("file.encoding"));

try {
FileUtils.copyFile(new File("/var/aiplatform/test/1.jpg"),new File("/var/aiplatform/test/张小泉呵呵_111_zxq.com.jpg"));
} catch (IOException e) {
e.printStackTrace();
}
}
}

如下pom.xml 可以将 commons-io打到同一个jar包中。
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.xx.test</groupId>
    <artifactId>testfile</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.6</version>
        </dependency>
    </dependencies>

    <build>
      <finalName>testfile</finalName>
        <plugins>
            <!-- maven-assembly-plugin -->
            <!-- 打包方式:mvn package assembly:single  -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.5.5</version>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>com.xx.test.EncodeTest</mainClass>
                        </manifest>
                    </archive>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>assembly</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
maven package  # 打包成功

 java -jar testfile-jar-with-dependencies.jar  ## 执行文件复制成功。