首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么同一个JAVA程序在Windows和Linux等不同平台上的工作方式不同?

为什么同一个JAVA程序在Windows和Linux等不同平台上的工作方式不同?
EN

Stack Overflow用户
提问于 2015-05-08 01:59:20
回答 1查看 718关注 0票数 4

相同的JAVA程序在不同的平台上的工作方式也不同。

例如,我编写了一个JAVA,用于将存储在文件夹中的不同Tiff文件组合到多页Tiff。

请在下面的节目中找到。

代码语言:javascript
复制
 public String merge(String dirPath) {
        String inputDir = dirPath;
        File faxSource = new File(inputDir);
        File file[] = faxSource.listFiles();

        int numImages = file.length;
        String name = "";
        List<BufferedImage> images = new ArrayList<BufferedImage>();
        Arrays.sort(file, new Comparator<File>() {
            public int compare(File f1, File f2) {
                return Long.compare(f1.lastModified(), f2.lastModified());
            }
        });
        try {
            for (int i = 0; i < numImages; i++) {
                name = name + file[i].getName();
                SeekableStream ss = new FileSeekableStream(file[i]);
                ImageDecoder decoder = ImageCodec.createImageDecoder("tiff",
                        ss, null);

                int numPages = decoder.getNumPages();
                for (int j = 0; j < numPages; j++) {
                    PlanarImage op = new NullOpImage(
                            decoder.decodeAsRenderedImage(j), null, null,
                            OpImage.OP_IO_BOUND);
                    images.add(op.getAsBufferedImage());
                }
            }

            // name=UUID.randomUUID().toString()+".tiff";

            TIFFEncodeParam params = new TIFFEncodeParam();
            params.setCompression(TIFFEncodeParam.COMPRESSION_DEFLATE);
            OutputStream out = new FileOutputStream(inputDir + "\\" + name);
            ImageEncoder encoder = ImageCodec.createImageEncoder("tiff", out,
                    params);
            // encoder.
            List<BufferedImage> imageList = new ArrayList<BufferedImage>();
            for (int i = 1; i < images.size(); i++) {
                imageList.add(images.get(i));
            }
            params.setExtraImages(imageList.iterator());
            encoder.encode(images.get(0));
            out.close();
        } catch (Exception e) {

        }
        return inputDir + "\\" + name;
    }

假设该文件夹包含4个tiff图像(A.tiff、B.tiff、C、.tiff、D.tiff).These Tiff文件按顺序从S#下载。

如果我在windows中运行上述程序,它正在按顺序A.tiff+B.tiff+C.tiff+D.tiff.进行排序

如果我在Amazon中运行相同的程序,将得到输出A.tiff+B.tiff+D.tiff+C.tiff.。

知道为什么相同的JAVA代码在Windows和Linux中的运行方式不同吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-05-08 04:31:46

检查Linux上的文件系统;对EXT3的修改日期的精度(我猜它正在使用)是1秒。如果您在一秒钟内下载两个文件,它们可能都有相同的时间。

另一方面,Windows通常使用NTFS,它在文件时间上具有100纳秒的精度。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30114601

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档