简体   繁体   English

原始文件和克隆文件之间的大小不同(java)

[英]Different size between original and cloned file(java)

am cloning xml file in my java code in a such way: 我以这种方式在我的Java代码中克隆xml文件:

 public boolean isCrcCorrect(Path path) throws IOException, XPathExpressionException {
    ByteArrayOutputStream output = new ByteArrayOutputStream();

    if (!fileData.currentFilePath.equals(path.toString())) {
        parseFile(path);
    }

    List<String> file_lines = Files.readAllLines(path);
    //BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(output));
    BufferedWriter bw = new BufferedWriter(new FileWriter(new File("f:\\Projects\\iqpdct\\iqpdct-domain\\src\\main\\java\\de\\iq2dev\\domain\\util\\debug.xml")));

    for (int i = 0; i < file_lines.size(); i++) {
        if (i != 0) {
            bw.write("\n");
        }

        if (file_lines.get(i).equals("  <Stamp crc=\"3916602279\"><Checker name=\"IODD-Checker V1.1.1\" version=\"V1.1.1.0\"/></Stamp>")) {
            bw.write("  <Stamp crc=\"\"><Checker name=\"IODD-Checker V1.1.1\" version=\"V1.1.1.0\"/></Stamp>");
        } else {
            bw.write(file_lines.get(i));
        }

        System.out.println(file_lines.get(i));
    }
    bw.flush();
    bw.close();

    crc.reset();
    crc.update(output.toByteArray());

    //debug
    System.out.println(crc.getValue());
    System.out.println(fileData.file_crc);
    //return fileData.file_crc == crc.getValue();
    return false;
}

I need to modiy attribute in xml (for debug I manualy made it in cycle). 我需要在xml中修改属性(为进行调试,我手动使其在循环中进行)。 I required this clone for checksum calculating. 我需要此克隆进行校验和计算。 Result file "debug.xml" is identical to source (InteliJ IDEA told so), but size is different : source: 41395, clone:40608 , so consequently I have incorrect checksum (CRC32 function) 结果文件“ debug.xml”与源文件相同(InteliJ IDEA表示),但大小不同源文件:41395,clone:40608 ,因此我的校验和不正确(CRC32函数)
What can causes this? 是什么原因造成的?

Just a guess, but you seem to hardcode new lines as \\n . 只是一个猜测,但是您似乎将新行硬编码为\\n Would it be possible that your input file has Windows style line endings and you are modifying them with your code ? 输入文件是否可能具有Windows样式行的结尾并且您正在使用代码对其进行修改?

Not sure here...but when you are replacing the line <Stamp crc=\\"3916602279\\"><Checker name=\\"IODD-Checker V1.1.1\\" version=\\"V1.1.1.0\\"/></Stamp> with <Stamp crc=\\"\\"><Checker name=\\"IODD-Checker V1.1.1\\" version=\\"V1.1.1.0\\"/></Stamp> , perhaps that is causing the difference? 不确定这里...但是当您替换行<Stamp crc=\\"3916602279\\"><Checker name=\\"IODD-Checker V1.1.1\\" version=\\"V1.1.1.0\\"/></Stamp><Stamp crc=\\"\\"><Checker name=\\"IODD-Checker V1.1.1\\" version=\\"V1.1.1.0\\"/></Stamp> ,可能是导致区别?

Just try not doing that and see if it produces the same sized clone file. 只是尝试不这样做,看看它是否生成相同大小的克隆文件。 Try that for me please. 请为我尝试一下。

Moreover, as Guillaume said, does the difference in \\n for windows and mac have different sizes? 而且,正如Guillaume所说,Windows和Mac的\\n的差异是否具有不同的大小?

In a completely different context, somebody correct me if I am wrong, but doesn't bw.close() automatically call bw.flush() ? 在完全不同的上下文中,如果我错了,有人会纠正我,但是bw.close()不会自动调用bw.flush()吗? I thought it does. 我认为是的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 与原始图像文件相比,ImageIO write会生成不同的文件大小 - ImageIO write produces a different file size as compared to the original image file Java IO-输出文件的大小大于原始文件的大小 - Java IO - Size of output file is larger than Original file 如何用java知道swf文件的原始大小(宽度和高度)? - How to know the original size (width and height) of a swf file with java? Java:如何将克隆的对象转换为它的原始子类? - Java: How do I cast a cloned object to it's original subclass? java为什么文件大小与操作系统不同 - java Why file size is different with operation system Java:目标文件夹中的Zip文件大小大于资源中的原始大小,不会解压缩 - java: Zip file size in target folder is bigger than original size in resources, won't unzip Jar文件:为什么提取然后压缩jar文件创建一个与原始文件大小不同的文件? - Jar files: why does extracting then compression a jar file create a file of a different size to the original? 如何在java中找到克隆对象和orignal对象之间的区别? - How to find difference between cloned object and orignal object in java? 如何在java中获取图像的原始大小 - how to get the original size of the image in java 在java中获取原始文件名? - Get the original file name in java?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM