Why does the same JAVA program work differently on different platforms such as Windows and Linux?

The same world of the JAVA program works differently on different platforms.

For example, I wrote JAVA to combine various Tiff files stored in a folder in Multi Tiff.

Please find below program.

 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;
    }

Suppose the folder contains 4 tiff images (A.tiff, B.tiff, C, .tiff, D.tiff). These Tiff files are loaded from S # in order.

If I run the above program on a Windows server, it sorts in the order A.tiff + B.tiff + C.tiff + D.tiff .

If I run the same program on Amazon EC2 Linux, I get the output A.tiff + B.tiff + D.tiff + C.tiff .

Any idea why the same JAVA code works differently on Windows and Linux?

+4
1

Linux-; EXT3, , 1 . , .

Windows, , NTFS, 100 .

+2

All Articles