Unix file path not working to retrieve file
I have an application I developed on a Windows machine to generate some XML and then later read it. Well when I generate on my Windows machine it works fine, and then I can read it with no problem. When I generate on the Unix machine, It works fine, but I can not read the file at all. The path is correct, the file is there, Java just can't read it for some reason, I get a FileNotFoundException. It gets the path from a properties file, then adds the filename to the path and tries to retrieve it. The path looks like this /pages/content/net/tool/Custom.xml and when I vi the file vi can read it fine. So anyone run across this before, not being able to read the file at all? To generate I use betwixt and to read I use digester.
Thanks in advance.
This is the code trying to read the file
//the method to get the properties file
public Properties getRepositoryProps() throws CommonException {
Properties props = new Properties() ;
InputStream input = this.getClass().getClassLoader().getResourceAsStream("repository.properties") ;
try {
props.load(input) ;
input.close() ;
}
catch (Exception e) {
throw new CommonException(this.getClass(), "The RepositoryReader threw an exception trying to get the properties file : " + e.getMessage(), e) ;
}
return props ;
}
//the method used to read the file
public File execute(String fileName) throws CommonException {
if (fileName != null && fileName.length() > 0){
PropertiesReader reader = new PropertiesReader() ;
String repositoryPath = reader.getRepositoryProps().getProperty(PricingResources.REPOSITORY_DIR) ;
File file = new File(repositoryPath + this.checkSlash(fileName)) ;
return file ;
}
else {
throw new CommonException(RepositoryReader.class,
"The File path in RepositoryReader is null or empty.") ;
}
}
//the way in which it all gets called
RepositoryReader repository = new RepositoryReader() ;
File rulesFile = repository.execute(rulesFilePath) ;
Thanks
The problem occurs in the read process, my code works fine, when I just place a document in the document repository, but if I generate a document using my application on a xNIX environment, the RepositoryReader cannot find the file, giving me a FileNotFoundException, on Windows if I generate it works fine. When I look at the path the FileNotFoundException kicks out, and paste into a console to have VI read it, I can see the file fine and everything looks great, my application just can't read it. Any clues?
I am going to give you the output here, and all of the configuration info as well and the checkSlash method too. But I suspect what is happening is some kind of stream/os control is holding on to the file and not letting someone take a look at it in the application level. If it's not that then it's a permission issue, which I chmod'ed the file and made rw-rw-r-- (it was rw-r--r--)just like the files that already work. Also I winSCP'ed into the box and tried a simple overwrite with another file of the same name and got a permision denied.
my application level exception :
com.spectra.common.CommonException:
/pages/content/net/tool/OpFinderCategoryReview.xml
(No such file or directory)
the real exception thrown by the application:
Caused by: java.io.FileNotFoundException:
/pages/content/net/tool/OpFinderCategoryReview.xml
(No such file or directory)
/*this method checks the file name passed in and see if it leads
with a slash to cap on the end of the path from the properties file
which is /pages/content/net/tool/ */
private String checkSlash(String fileName) {
if(fileName != null && !fileName.startsWith("/"))
return "/"+fileName ;
return fileName ;
}
/*I use betwixt to write out the XML for me and then I try and use it but it fails . this is the way I call betwixt */
try {
WizardProduct wizProduct = (WizardProduct)request.getSession().getAttribute(PricingResources.WIZARD) ;
String fileName = CommonUtil.checkSlash(this.createFileName(wizProduct)) ;
int pageId = this.createPage(wizProduct,fileName) ;
GenerateProduct genProduct = new GenerateProduct() ;
Product product = genProduct.doExecute(wizProduct, pageId) ;
PropertiesReader reader = new PropertiesReader() ;
String path = reader.getRepositoryProps().getProperty(PricingResources.REPOSITORY_DIR) ;
FileWriter fileWriter = new FileWriter(new File(path + fileName));
BeanWriter writer = new BeanWriter(fileWriter);
writer.getBindingConfiguration().setMapIDs(false) ;
writer.enablePrettyPrint();
XMLIntrospector introspector = writer.getXMLIntrospector( );
introspector.getConfiguration().setWrapCollectionsInElement(false);
writer.write("product", product);
writer.flush();
writer.close() ;
fileWriter.close() ;
}
/*
The read file process works fine in every scenario EXCEPT when I generate a document from my application and then try to read it. The problem is not in reading it normally, it's reading it only on a Linux machine after I generate a doc, not on windows.
Thanks