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.

[765 byte] By [rutherford218a] at [2007-11-26 18:27:59]
# 1

It would help to see the code that's trying to read the file.

When you post code, please use[code] and [/code] tags as described in [url=http://forum.java.sun.com/help.jspa?sec=formatting]Formatting tips[/url] on the message entry page. It makes it much easier to read.

jverda at 2007-7-9 6:02:09 > top of Java-index,Java Essentials,Java Programming...
# 2

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

rutherford218a at 2007-7-9 6:02:09 > top of Java-index,Java Essentials,Java Programming...
# 3
And where exactly is the problem occurring, and with which input?
jverda at 2007-7-9 6:02:09 > top of Java-index,Java Essentials,Java Programming...
# 4

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?

rutherford218a at 2007-7-9 6:02:09 > top of Java-index,Java Essentials,Java Programming...
# 5

The clue would be in the filename (I think that's what jverd was referring to when he wrote "with which input"). So far you haven't posted any examples.

And the existence of a "checkSlash" method makes me suspicious that it might be part of the problem.

Edit: Oops, sorry, you did provide an example in your original post. Did that come from debug output that wasn't in your posted code? I would write whatever you are passing to the new File() constructor to System.out and look at it there.

Message was edited by:

DrClap

DrClapa at 2007-7-9 6:02:09 > top of Java-index,Java Essentials,Java Programming...
# 6

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

rutherford218a at 2007-7-9 6:02:09 > top of Java-index,Java Essentials,Java Programming...