• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Peter Rooke
  • Himai Minh
Bartenders:
  • Piet Souris
  • Mikalai Zaikin

What FileReader expects

 
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All, I have the following program in which FileReader expects an argument. I am wondering why I can't get away with the full ftp path to the file.



Any help is greatly appreciated!
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
FR expects a file name, that is, a path to a file on the local file system. What you gave it is a URL that requires an FTP client to resolve. FR is not an FTP client, and it's not meant for handling arbitrary URLs. You can't give it an HTTP URL either, even though that may eventually resolve to the static contents of a single file.
 
Dan Grindstaff
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Thank you for the response. It sounds like I will need to import the file first? But I am wondering if there is a way around this?
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dan Grindstaff wrote:Hi, Thank you for the response. It sounds like I will need to import the file first? But I am wondering if there is a way around this?



If by "import" you mean copy it to your local file system by some other means, then, yes, that's one option.

Note also that there do exist FTP clients for Java, which you can find by googling. It's just that the FileReader class isn't one of them.
 
Dan Grindstaff
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, I added the following code to try and fetch the file though I would rather just erad it from where it sits.

 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dan Grindstaff wrote:Ok, I added the following code to try and fetch the file though I would rather just erad it from where it sits.



Does that FTP client offer a "spit back the contents in a stream but don't save them to a file" operation? If so, then that's what you'd use. If not, then you could see if there's some other FTP client that does so, or some other service on that host making that file available where you could do that, with a corresponding client.

For example: Apache commons FTPClient.retrieveFileStream(java.lang.String)
 
Dan Grindstaff
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have switched gears, trying to find an FTP solution and THEN I can concentrate on the CSV parser. I have tried this code for FTP:

which returns the following error:
I am completely stuck right now.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It looks like you're trying to use "ftp://<some address>/production" as the host name or address, when in fact it should just be "<some address>".
 
Dan Grindstaff
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, no errors when I just have the address in there, however the file I need is still a couple directories further into the url. Here is the code:
and here is the error message:
 
Dan Grindstaff
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, this code does not throw errors:
But I have a stupid question. Where am I downloading the file to?
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Note that the root that the FTP server shows you will not necessarily be that hosts file system root. Typically it is not. You have to either know ahead of time what the path will be relative to wherever the FTP sets your user's root at, or you have to look for it. The FTP protocol provides a directory listing operation, and I would assume your client library provides access to it.
 
Dan Grindstaff
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All Right! Making progress I found the file in the code directory but it is empty! Any ideas why it would be empty?
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dan Grindstaff wrote:But I have a stupid question. Where am I downloading the file to?



Well, you have this:


So it's going to the path specified by whatever you set filename to. If you didn't make it an absolute path, it will be relative to whatever the current directory was for the JVM at the time it was started. It's better not to rely on that, but to specify an absolute path instead. Or, if you have to rely on it, you can ask the File object referred to by filename what its absolute path is.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dan Grindstaff wrote:All Right! Making progress I found the file in the code directory but it is empty! Any ideas why it would be empty?



No, I don't. I thought maybe you didn't close the FOS, but it looks like you did.

I'd start digging into the docs for the client library, see what kind of diagnostics it can give you, add some println() statements so you can see what's going on, maybe read a stream first instead of just retreiveFile, and see what's in that stream.

In other words, as with any debugging, you have to break it down into smaller and smaller pieces and to find out exactly where the problem is occurring.
 
Dan Grindstaff
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could you please give me an example of how to use RetrieveFile? Thanks Never mind I see I am already using it in one place. Duh!
 
Dan Grindstaff
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, I have some code here that is working:

but I need a way to pass the line read from this code to the reader in :

 
Dan Grindstaff
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It seems like I am getting really close with the following code:



But I am mangling up something in the write section.
 
Dan Grindstaff
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, I finally got some code to accomplish this:



I would appreciate any help in cleaning it up and/or hints on how to further simplify. Thanks!
 
Dan Grindstaff
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dan Grindstaff wrote:Ok, I finally got some code to accomplish this:



I would appreciate any help in cleaning it up and/or hints on how to further simplify. Thanks!

 
Get meta with me! What pursues us is our own obsessions! But not this tiny ad:
Master Gardener Program
https://coderanch.com/t/771761/Master-Gardener-Program
reply
    Bookmark Topic Watch Topic
  • New Topic