solaris 10,java 6,file.exists 看不到现有文件
Posted
技术标签:
【中文标题】solaris 10,java 6,file.exists 看不到现有文件【英文标题】:solaris 10, java 6 , file.exists cant see the existing file 【发布时间】:2011-12-23 08:18:28 【问题描述】:我有一个将数百万个小文件组成 tar 档案的代码,因此我决定使用我的 solaris 机器的 /tmp 文件夹。然后我创建了一个 ramdisk 而不是 /tmp 我现在使用我创建的 ramdisk (/ramdata).. 这是我为完成任务所做的:
首先我尝试在 ramdisk 中创建 tar 存档,然后移动到目标目录,但是当我这样做时,当文件存在时 java 的 File.exists() 未能返回 true。然后我将目录更改为磁盘上的目录 (opt/dist/dist1/cdrepo) 以放置我的 tar 文件,并且在那里成功创建了 tar 文件,但是 File.exists() 在文件存在时未能返回 true。
然后我看到这篇帖子Alternative to File.exists() in Java 并相应地更改了我的代码,以便 NFS 将重置缓存,但它也没有工作。
任何人都可以就它发生的原因以及我如何解决这个问题提出任何解决方案或想法吗?谢谢大家。
我使用的是Java6U21,它是一台Solaris 10机器..
下面是我尝试的最终代码..:我知道该代码有一些来自我之前尝试的迹象-例如我实例化 File 对象并使用 fileExists 变量检查其存在的地方...-不会绝对可以按预期工作,但是因为现在我只是想查看 File.exists() 的真实结果,所以我忽略了它们。主要的例外是在czf.take_md5这一行方法中,第一行是FileInputStream fis = new FileInputStream(filename);
public static synchronized void CreateZipFileFromSingleFolder(String folder,int CDNumber) throws Exception
CreateZipFile czf = new CreateZipFile();
System.err.println(folder + " tarlaniyor...");
Process p=null;
String tarName=CDFolderInfo.getID()+"_cd_"+CDNumber + ".tar ";
String tarFolder=CDFolderInfo.getPathRoot();
//String komut = "tar -cf " + tarFolder+"/"+tarName+" "+ folder;
String komut = "tar -cf " + "/opt/dist/dist1/cdrepo/"+tarName+" "+ folder;
try
System.err.println(komut + " ----- komutu ile tarlama yapilacak.......");
p = Runtime.getRuntime().exec(komut);
catch (IOException e)
// TODO Auto-generated catch block
e.printStackTrace();
try
p.waitFor();
catch (InterruptedException e)
// TODO Auto-generated catch block
e.printStackTrace();
System.err.println("system exit value: " + p.exitValue());
if(p.exitValue()==0)
Process p3=null;
p3=Runtime.getRuntime().exec("ls -l /opt/dist/dist1/cdrepo");
p3.waitFor();
if(p3.exitValue()==0)
System.err.println("LS CDREPO ICIN BASARILI OLARAK CALISTI...");
/*Process p4=null;
p4=Runtime.getRuntime().exec("ls -l " +tarFolder+"/"+tarName);
p4.waitFor();
if(p4.exitValue()==0)
System.err.println("LS TAR FOLDER ICIN BASARILI OLARAK CALISTI...");
*/
File f2=new File("/opt/dist/dist1/cdrepo/"+tarName);
System.err.println("Absolute Path : "+f2.getAbsolutePath());
System.err.println(" Path : "+f2.getPath());
System.err.println("Canonical Path : "+f2.getCanonicalPath());
System.err.println("is File : "+f2.isFile());
System.err.println("Length : "+f2.length());
System.err.println("is Hidden : "+f2.isHidden());
if(f2.exists())
System.err.println("Dosya cdrepoda...");
else
System.err.println("dosya derepoda degil...");
f2=null;
try
czf.take_md5("/opt/dist/dist1/cdrepo/"+tarName);
System.err.println("MD5 alma succeed...");
catch (Exception e)
// TODO Auto-generated catch block
e.printStackTrace();
/*
if(f2.exists())
System.err.println("Tar tasima succeed..");
else
System.err.println("move komutu basarili , ama dosyayi bulamiyorum...");
f2=null;*/
else
System.err.println("p == 0 yanlis... Tar olusturma failed..");
/*System.err.println("tar file existence will be checked..");*/
File f=new File(tarFolder+"/"+tarName);
boolean fileExists = FileUtils.waitFor(f, 10);
if(fileExists)
System.err.println("tar succeeded .... " + tarFolder+"/"+tarName);
System.err.println("tar file existence PASSED ..");
else
System.err.println("tar process didnt fail, but actually failed...");
f=null;
/* Process p2 = Runtime.getRuntime().exec("mv " + tarFolder+"/"+tarName+" "+ "cdrepo/"+tarName);
p2.waitFor();*/
//if(p2.exitValue()==0)
//System.err.println("p2 == 0 kontrolu dogru....");
Process p1=null;
try
p1 = Runtime.getRuntime().exec("rm -rf " + folder );
catch (IOException e)
// TODO Auto-generated catch block
e.printStackTrace();
try
p1.waitFor();
if(p1.exitValue()==0)
System.err.println("Dizin silme tamamlandı... " + folder);
catch (InterruptedException e)
// TODO Auto-generated catch block
e.printStackTrace();
//
输出是:
/ramdata/cdtemp_125_1 tarlaniyor...
tar -cf /opt/dist/dist1/cdrepo/125_cd_1.tar /ramdata/cdtemp_125_1 ----- komutu ile tarlama yapilacak.......
system exit value: 0
LS CDREPO ICIN BASARILI OLARAK CALISTI...
Absolute Path : /opt/dist/dist1/cdrepo/125_cd_1.tar
Path : /opt/dist/dist1/cdrepo/125_cd_1.tar
Canonical Path : /opt/dist/dist1/cdrepo/125_cd_1.tar
is File : false
Length : 0
is Hidden : false
dosya derepoda degil...
java.io.FileNotFoundException: /opt/dist/dist1/cdrepo/125_cd_1.tar (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at java.io.FileInputStream.<init>(FileInputStream.java:66)
at staticcdbuildernewver.CreateZipFile.take_md5(CreateZipFile.java:34)
at staticcdbuildernewver.OracleSideDbOps.CreateZipFileFromSingleFolder(OracleSideDbOps.java:723)
这是 Jayan 建议的 TRUSS 命令的输出: 似乎它无法解析路径:(但由于我不擅长 UNIX linux,我几乎无法理解它的含义..
/37: 1179.9948 write(2, " L S C D R E P O I C".., 41) = 41
/21: 1179.9948 lwp_cond_wait(0x08234D48, 0x08234D30, 0xB60D6C08, 0) = 0
/21: 1179.9949 mprotect(0xFEC60000, 4096, PROT_READ) = 0
/37: 1179.9950 Incurred fault #6, FLTBOUNDS %pc = 0xFE4B49A1
/37: siginfo: SIGSEGV SEGV_ACCERR addr=0xFEC60280
/37: 1179.9950 Received signal #11, SIGSEGV [caught]
/37: siginfo: SIGSEGV SEGV_ACCERR addr=0xFEC60280
/21: 1179.9950 mprotect(0xFEC60000, 4096, PROT_READ|PROT_WRITE) = 0
/37: 1179.9950 lwp_sigmask(SIG_SETMASK, 0xFFBFFEFF, 0x0000FFF7) = 0xFFBFFEFF [0x0000FFFF]
/37: 1179.9951 setcontext(0xB5A6C1C0)
/21: 1179.9951 mprotect(0xFEE20000, 4096, PROT_NONE) = 0
/21: 1179.9957 mprotect(0xFEE20000, 4096, PROT_READ) = 0
/21: 1179.9958 lwp_cond_signal(0x0849D448) = 0
/37: 1179.9958 lwp_cond_wait(0x0849D448, 0x0849D430, 0x00000000, 0) = 0
/21: 1179.9959 lwp_cond_signal(0x084BDC48) = 0
/39: 1179.9959 lwp_cond_wait(0x084BDC48, 0x084BDC30, 0x00000000, 0) = 0
/37: 1179.9959 write(2, "\n", 1) = 1
/39: 1179.9959 mprotect(0xB5BDC000, 12288, PROT_READ|PROT_WRITE) = 0
/37: 1179.9960 write(2, " / o p t / d i s t / d i".., 15) = 15
/39: 1179.9960 lwp_sigmask(SIG_SETMASK, 0x00000004, 0x00000000) = 0xFFBFFEFF [0x0000FFFF]
/37: 1179.9961 write(2, "\n", 1) = 1
/39: 1179.9961 lwp_sigmask(SIG_SETMASK, 0xFFBFFEFF, 0x0000FFF7) = 0xFFBFFEFF [0x0000FFFF]
/37: 1179.9962 write(2, "\n", 1) = 1
/39: 1179.9962 lwp_exit()
/37: 1179.9963 write(2, " / o p t / d i s t / d i".., 15) = 15
/37: 1179.9964 write(2, "\n", 1) = 1
/37: 1179.9964 write(2, "\n", 1) = 1
/37: 1179.9965 write(2, " A b s o l u t e P a t".., 52) = 52
/37: 1179.9966 write(2, "\n", 1) = 1
/37: 1179.9967 write(2, " P a t".., 52) = 52
/37: 1179.9967 write(2, "\n", 1) = 1
/37: 1179.9968 resolvepath("/opt/dist/dist1/cdrepo/125_cd_1.tar ", 0xB5A6C3C0, 1024) Err#2 ENOENT
/37: 1179.9969 resolvepath("/opt/dist/dist1/cdrepo", "/opt/dist/dist1/cdrepo", 1024) = 22
/37: 1179.9970 write(2, " C a n o n i c a l P a".., 53) = 53
/37: 1179.9970 write(2, "\n", 1) = 1
/37: 1179.9971 stat64("/opt/dist/dist1/cdrepo/125_cd_1.tar ", 0xB5A6C6C0) Err#2 ENOENT
/37: 1179.9972 write(2, " i s F i l e : f a".., 15) = 15
/37: 1179.9972 write(2, "\n", 1) = 1
/37: 1179.9973 stat64("/opt/dist/dist1/cdrepo/125_cd_1.tar ", 0xB5A6C700) Err#2 ENOENT
/37: 1179.9974 write(2, " L e n g t h : 0", 10) = 10
/37: 1179.9975 write(2, "\n", 1) = 1
/37: 1179.9975 stat64("/opt/dist/dist1/cdrepo/125_cd_1.tar ", 0xB5A6C6C0) Err#2 ENOENT
/37: 1179.9976 write(2, " i s H i d d e n : ".., 17) = 17
/37: 1179.9977 write(2, "\n", 1) = 1
/37: 1179.9977 write(2, " / o p t / d i s t / d i".., 15) = 15
/37: 1179.9978 write(2, "\n", 1) = 1
/37: 1179.9979 write(2, "\n", 1) = 1
/37: 1179.9979 stat64("/opt/dist/dist1/cdrepo/125_cd_1.tar ", 0xB5A6C700) Err#2 ENOENT
/37: 1179.9980 write(2, " d o s y a d e r e p o".., 23) = 23
/37: 1179.9980 write(2, "\n", 1) = 1
/37: 1179.9981 open64("/opt/dist/dist1/cdrepo/125_cd_1.tar ", O_RDONLY) Err#2 ENOENT
/37: 1179.9983 write(2, " j a v a . i o . F i l e".., 95) = 95
/37: 1179.9984 write(2, "\n", 1) = 1
/37: 1179.9986 write(2, "\t a t j a v a . i o .".., 47) = 47
/37: 1179.9986 write(2, "\n", 1) = 1
/37: 1179.9987 write(2, "\t a t j a v a . i o .".., 60) = 60
/37: 1179.9987 write(2, "\n", 1) = 1
/37: 1179.9988 write(2, "\t a t j a v a . i o .".., 59) = 59
/37: 1179.9988 write(2, "\n", 1) = 1
/37: 1179.9989 write(2, "\t a t s t a t i c c d".., 71) = 71
/37: 1179.9990 write(2, "\n", 1) = 1
/37: 1179.9990 write(2, "\t a t s t a t i c c d".., 97) = 97
/37: 1179.9991 write(2, "\n", 1) = 1
/37: 1179.9991 write(2, "\t a t s t a t i c c d".., 68) = 68
/37: 1179.9992 write(2, "\n", 1) = 1
/37: 1179.9993 write(2, "\t a t s t a t i c c d".., 87) = 87
/37: 1179.9993 write(2, "\n", 1) = 1
/37: 1179.9994 write(2, "\t a t s t a t i c c d".., 55) = 55
/37: 1179.9995 write(2, "\n", 1) = 1
/37: 1179.9995 write(2, "\t a t j a v a . l a n".., 41) = 41
【问题讨论】:
会不会是 Solaris 用户没有足够的访问权限来获取目录中的文件列表? 我从 ssh 连接窗口使用这个 java 程序,并且我用 root 用户连接.. 是否有任何情况下 root 没有目录列表权限? Ramdisk 不是 NFS 挂载的。 我不擅长 Linux UNIX 系统,我只是看到那个帖子并尝试以防万一.. :) 你能不能用 truss所有问题都在于 tarName 变量定义中的额外空间..只需删除额外的空间..一切都会正常工作..
【讨论】:
【参考方案2】:试一试
if(f2.exists())
System.err.println("Dosya cdrepoda...");
else
System.err.println("dosya derepoda degil...");
f2.getParentFile().mkdirs();
【讨论】:
所有需要的目录都是预先创建的。但我希望 f2.exists() 返回 true,在这种情况下,您只需在它为 false 时执行操作,这意味着我仍然会遇到错误。 .如果我误解了请澄清..以上是关于solaris 10,java 6,file.exists 看不到现有文件的主要内容,如果未能解决你的问题,请参考以下文章
Solaris 10 中的 libv8 安装(SPARC 架构,gcc 4.6.3)
带有 MySQL 5.6 的 Solaris 10 中的 MySQL 性能问题
在Solaris 10 x86下用gcc编译Poco 1.4.6