相同的JAVA程序在不同的平台上的工作方式也不同。
例如,我编写了一个JAVA,用于将存储在文件夹中的不同Tiff文件组合到多页Tiff。
请在下面的节目中找到。
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中的运行方式不同吗?
发布于 2015-05-08 04:31:46
检查Linux上的文件系统;对EXT3的修改日期的精度(我猜它正在使用)是1秒。如果您在一秒钟内下载两个文件,它们可能都有相同的时间。
另一方面,Windows通常使用NTFS,它在文件时间上具有100纳秒的精度。
https://stackoverflow.com/questions/30114601
复制相似问题