|
Hi George, Now that we see your code, Joe's answer, and I assume the articles David pointed to, are exactly right. All you need to give it is the file path: '/TecnoXML/aces.xml' It doesn't matter if it's an XML or any other type of stream file, except that you wouldn't use a Reader in the case of a binary file. To speed up things, you probably want to use a BufferedReader. I was under the impression that you needed a file URL using the file: protocol. Wish I had known before, because I spent some review time this morning. First, no syntax with "file:" plus anything would *ever* have worked, because that's a URL, and FileReader constructors are available only for File, File Descriptor, or a pathname String. Since I spent the time, this info may be helpful to others at some point. I was on top of the file URL thing in 1998, but I just haven't had a particular use for it in quite a while. And Windows, per usual, causes complications with direct file URL's. RFC 1738 is pretty much the bible on URL's, including the file: protocol. It's at: http://rfc.net/rfc1738.html The info I gave before would work on a Windows box, but not on most other systems becasue "/" is generally the root of the file system. The safest, most generic thing to do when you actually need a file URL is to create a File object as normal, then use the result of either the toURL() or toURI().toURL() methods. Then you don't have to worry about syntax, slashes, etc. becasue Java will do it for you. I've included a brief program below that shows pertinent information. Some results are: --------------------------- Windows, as: java FileInfo c:\adir\ACES.xml AbsoluteFile: c:\adir\ACES.xml AbsolutePath: c:\adir\ACES.xml CanonicalFile: C:\adir\ACES.xml CanonicalPath: C:\adir\ACES.xml toURI: file:/c:/adir/ACES.xml toURL: file:/c:/adir/ACES.xml URI to URL: file:/c:/adir/ACES.xml --------------------------- AS/400: java with '/TecnoXML/ACES.xml' passed as the argument: AbsoluteFile: /TecnoXML/ACES.xml AbsolutePath: /TecnoXML/ACES.xml CanonicalFile: /TecnoXML/ACES.xml CanonicalPath: /TecnoXML/ACES.xml toURI: file:/TecnoXML/ACES.xml toURL: file:/TecnoXML/ACES.xml URI to URL: file:/TecnoXML/ACES.xml --------------------------- Here's the program: import java.io.*; import java.net.*; public class FileInfo { public static void main( String[] args ) { File f; if( args.length != 1 ) { System.out.println( "FileInfo expects exactly 1 filename." ); System.out.println( "FileInfo ends." ); return; } try { f = new File( args[0] ); System.out.println( "AbsoluteFile: " + f.getAbsoluteFile() ); System.out.println( "AbsolutePath: " + f.getAbsolutePath() ); System.out.println( "CanonicalFile: " + f.getCanonicalFile() ); System.out.println( "CanonicalPath: " + f.getCanonicalPath() ); System.out.println( "toURI: " + f.toURI() ); System.out.println( "toURL: " + f.toURL() ); System.out.println( "URI to URL: " + f.toURI().toURL() ); } catch( Exception e ) { System.out.println( "Exception: " + e.getMessage() ); } } // end main } // end class FileInfo Joe Sam Joe Sam Shirah - http://www.conceptgo.com conceptGO - Consulting/Development/Outsourcing Java Filter Forum: http://www.ibm.com/developerworks/java/ Just the JDBC FAQs: http://www.jguru.com/faq/JDBC Going International? http://www.jguru.com/faq/I18N Que Java400? http://www.jguru.com/faq/Java400 ----- Original Message ----- From: "George Lopez" <georgerl@xxxxxxxxxxxx> To: "Java Programming on and around the iSeries / AS400" <java400-l@xxxxxxxxxxxx> Sent: Thursday, May 11, 2006 10:43 AM Subject: Re: Format of file format in the IFS directory in JAVA > Sorry but it does not work still. I wonder if it's some kind of > authority problem? I wonder if someone else have ever used a .xml file > in AS400 IFS directory to access and parse in JAVA? Any example where > the correct format worked? Thank you. > > This is what I used: > file://TecnoXML/aces.xml > This is the error: > java.io.FileNotFoundException: No such path or directory. > file:/TecnoXML/aces.xml > > This is what I used: > file:////TecnoXML/aces.xml > This is the error: > java.io.FileNotFoundException: No such path or directory. > file:/TecnoXML/aces.xml > > This is part of my JAVA code. Where string variable *file* is filled > with above values. And the line *xr.parse(new InputSource(r)); *is where > I get the error. > FileReader r = new FileReader(file); > System.out.println("File reader successful"); > *xr.parse(new InputSource(r));* > System.out.println("Parse successful"); > > Joe Sam Shirah wrote: > > > Hi George, > > > > Neither of your examples in the message below match what I posted. The > >1 or 3 slashes are *only* for the "file:" protocol. Any slashes or > >backslashes in the file path are separate and additional. > > > >>From your last ones: > > > > > file:/TecnoXML/aces.xml > > > >is completely invalid. > > > > > > > file:///TecnoXML/aces.xml > > > >doesn't work ( file: + 2 slashes ), although some docs make it appear that > >it should. > > > > > >My examples, where myFilePath is "/TecnoXML/ACES.xml" were: > > > > "file:///" + myFilePath; > > > > "file:/" + myFilePath; > > > > Result: > > > > "file:////TecnoXML/ACES.xml" > > > > > > "file://TecnoXML/ACES.xml" > > > > Let me know if those don't work; maybe I'll have some time tomorrow to > >check it out if that's the case, but IIRC, should do. > > > > > > Joe Sam > > > >Joe Sam Shirah - http://www.conceptgo.com > >conceptGO - Consulting/Development/Outsourcing > >Java Filter Forum: http://www.ibm.com/developerworks/java/ > >Just the JDBC FAQs: http://www.jguru.com/faq/JDBC > >Going International? http://www.jguru.com/faq/I18N > >Que Java400? http://www.jguru.com/faq/Java400 > > > > > >----- Original Message ----- > >From: "George Lopez" <georgerl@xxxxxxxxxxxx> > >To: "Java Programming on and around the iSeries / AS400" > ><java400-l@xxxxxxxxxxxx> > >Sent: Wednesday, May 10, 2006 5:27 PM > >Subject: Re: Format of file format in the IFS directory in JAVA > > > > > > > > > >>Yes my JAVA program is not locating files in the AS400 IFS directory. I > >>am running this program in the AS400 which also means I moved the jar > >>and classes from my PC to the IFS directory too. The 1 to 3 slashes > >>still does not work (Look below). The syntax I am using in Windows is > >>C:\\Developement\\xml\\aces.xml. I also made sure this time I used the > >>same case for the directory and file. > >> > >>Thanks > >> > >> > >>file:/TecnoXML/aces.xml > >>java.io.FileNotFoundException: No such path or directory. > >>file:/TecnoXML/aces.xml > >> > >>file:///TecnoXML/aces.xml > >>java.io.FileNotFoundException: No such path or directory. > >>file:/TecnoXML/aces.xml > >> > >> > >>Joe Sam Shirah wrote: > >> > >> > >> > >>> Hi George, > >>> > >>> So I take it your question is how to locate files? > >>> > >>> To the best of my recollection, and I don't have time to double check > >>>now, technically the "file:" protocol requires three ( 3 ) slashes. It > >>>also, for reasons I forget, will ( usta ) work with one ( 1 ) slash. It > >>>will not work with two slashes. > >>> > >>> Examples for /TecnoXML/ACES.xml: > >>> > >>> "file:///" + myFilePath; > >>> > >>> "file:/" + myFilePath; > >>> > >>> Result: > >>> > >>> "file:////TecnoXML/ACES.xml" > >>> > >>> > >>> "file://TecnoXML/ACES.xml" > >>> > >>> Incidentally, Java parsing for file structure will work with forward > >>>slashes even for Windows, so you can avoid intermixing slashes and > >>>backslashes. > >>> > >>> Still, it should work the same on all platforms. What syntax are you > >>>using on Windows? > >>> > >>> > >>> Joe Sam > >>> > >>>Joe Sam Shirah - http://www.conceptgo.com > >>>conceptGO - Consulting/Development/Outsourcing > >>>Java Filter Forum: http://www.ibm.com/developerworks/java/ > >>>Just the JDBC FAQs: http://www.jguru.com/faq/JDBC > >>>Going International? http://www.jguru.com/faq/I18N > >>>Que Java400? http://www.jguru.com/faq/Java400 > >>> > >>> > >>>----- Original Message ----- > >>>From: "George Lopez" <georgerl@xxxxxxxxxxxx> > >>>To: <java400-l@xxxxxxxxxxxx> > >>>Sent: Wednesday, May 10, 2006 2:20 PM > >>>Subject: Format of file format in the IFS directory in JAVA > >>> > >>> > >>> > >>> > >>> > >>> > >>>>I have an java xml parser developed in Eclipse. When I run the parser in > >>>>Websphere Development Studio and use the xml in my C: drive it works. > >>>>But if I put the xml in the ifs directory in the AS400 I get error > >>>>message below..... > >>>> > >>>>The IFS directory in the as400 is... > >>>>/TecnoXML/ACES.xml > >>>> > >>>> > >>>>Error if i use: /TecnoXML/ACES.xml > >>>>java.net.MalformedURLException: unknown protocol: > >>>> > >>>>Error if i use: file:///TecnoXML/ACES.xml > >>>>java.io.FileNotFoundException: No such path or directory. > >>>>file:/TecnoXML/Aces.xml > >>>> > >>>>Error if i use: file:\\\TecnoXML/ACES.xml > >>>>java.io.FileNotFoundException: No such path or directory. > >>>>file:\\\TecnoXML/ACES.xml > >>>> > >>>>-- > >>>>This is the Java Programming on and around the iSeries / AS400
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.