Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在Linux上使用Apache Commons Compression压缩文件时出现编码错误_Java_Encoding_Gzip_Apache Commons_Tar - Fatal编程技术网

Java 在Linux上使用Apache Commons Compression压缩文件时出现编码错误

Java 在Linux上使用Apache Commons Compression压缩文件时出现编码错误,java,encoding,gzip,apache-commons,tar,Java,Encoding,Gzip,Apache Commons,Tar,我正在使用ApacheCommonsAPI压缩来压缩文件。Windows 7运行良好,但在Linux(ubuntu 10.10-UTF8)中,文件名和文件夹名中的字符(例如“º”)被替换为“?” 在压缩或解压缩tar时,是否有任何参数应该传递给API 我正在使用tar.gz格式,下面是API示例 我正在尝试压缩的文件是在windows中创建的。。。有什么麻烦吗 守则: public class TarGzTest { public static void create

我正在使用ApacheCommonsAPI压缩来压缩文件。Windows 7运行良好,但在Linux(ubuntu 10.10-UTF8)中,文件名和文件夹名中的字符(例如“º”)被替换为“?”

在压缩或解压缩tar时,是否有任何参数应该传递给API

我正在使用tar.gz格式,下面是API示例

我正在尝试压缩的文件是在windows中创建的。。。有什么麻烦吗

守则:

    public class TarGzTest 
    {

    public static void createTarGzOfDirectory(String directoryPath, String tarGzPath) throws IOException
    {
        System.out.println("Criando tar.gz da pasta " + directoryPath + " em " + tarGzPath);
        FileOutputStream fOut = null;
        BufferedOutputStream bOut = null;
        GzipCompressorOutputStream gzOut = null;
        TarArchiveOutputStream tOut = null;

        try
        {
            fOut = new FileOutputStream(new File(tarGzPath));
            bOut = new BufferedOutputStream(fOut);
            gzOut = new GzipCompressorOutputStream(bOut);
            tOut = new TarArchiveOutputStream(gzOut);

            addFileToTarGz(tOut, directoryPath, "");
        }
        finally
        {
            tOut.finish();
            tOut.close();
            gzOut.close();
            bOut.close();
            fOut.close();
        }
        System.out.println("Processo concluído.");
    }

    private static void addFileToTarGz(TarArchiveOutputStream tOut, String path, String base) throws IOException
    {
        System.out.println("addFileToTarGz()::"+path);
        File f = new File(path);
        String entryName = base + f.getName();
        TarArchiveEntry tarEntry = new TarArchiveEntry(f, entryName);

        tOut.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);

        if(f.isFile())
        {
            tOut.putArchiveEntry(tarEntry);

            IOUtils.copy(new FileInputStream(f), tOut);

            tOut.closeArchiveEntry();
        }
        else
        {
            File[] children = f.listFiles();

            if(children != null)
            {
                for(File child : children)
                {
                    addFileToTarGz(tOut, child.getAbsolutePath(), entryName + "/");
                }
            }
        }
    }
}
(I抑制主方法;)


编辑(monkeyjluffy):我所做的更改是在不同的平台上始终具有相同的存档。然后计算的哈希值是相同的。

我找到了解决问题的方法

出于某种原因,java不尊重我的环境编码,并将其更改为cp1252

在解压文件之后,我只需进入文件夹,然后运行以下命令:

convmv --notest -f cp1252 -t utf8 * -r
它将所有内容递归地转换为UTF-8

问题解决了,伙计们

有关linux中编码问题的更多信息


谢谢大家的帮助。

你是说当你解压时,文件与原来不一样了吗?请显示您正在使用的确切代码。这可能与Windows与Linux中如何表示CR o LF有关吗???@jon skeet我编辑了问题,添加了代码和一些信息。@caarlos0:好的,这就是压缩部分。。。还有减压?你是如何查看“坏”文件的?@jon skeet我正在用“tar xzvf file.tar.gz”解压。。。