• Post Reply Bookmark Topic Watch Topic
  • New Topic

Allow User To Choose Where To Save File

 
travis Haycock
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey everyone,


Just like the subject says, how do you take a file in this context that is read from the cloud and pass it to for an example ? JFileChooser, I tried to use JFile choose to save the incoming file with no prevail. A File is not much use unless the user can save it where he likes in a responsive GUI design.. The code is below

 
Stefan Evans
Bartender
Posts: 1822
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JFileChooser sounds like the right sort of thing to me.
If you are doing a swing interface of course :-)

Your code sample doesn't employ JFileChooser anywhere though
And it appears to use a few variables that haven't been declared in your snippet: FilDbxPath, TargetLocalPath - what are these variables?

At which point is the user expected to choose where to save the file? Before, after or during this method?
To my mind you need to know which file you are writing to BEFORE you can open a FileOutputStream
 
travis Haycock
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey thanks for the reply, Yes this particular method here does not have JFileChooser in it I have tried to run it a few times with different variations of code but can't seem to get the file to be the already pre-selected file.

VARS

private String TargetLocalPath = " ", FileDbxPath = " ", FolderDbxPath="/";
String TargetDbxPath = "/", FileLocalPath = "", FolderLocalPath=".";

These are just essentially performing the source paths(dropbox) and target path (where file will be on local machine)

I was thinking about using it after the download was complete and then it being passed into the JFileChooser as it would be more simple?
 
Paul Clapham
Sheriff
Posts: 21889
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
travis Haycock wrote:I was thinking about using it after the download was complete and then it being passed into the JFileChooser as it would be more simple?


I don't understand what it is you intend to "pass into" a JFileChooser. The purpose of a JFileChooser is to ask the user to choose a file. Nothing more than that. It isn't necessary to pass any data to the JFileChooser, not before you display it and not after a file has been chosen by the user either.

Here's a high-level view of how your code should work:

1. Display the JFileChooser and allow the user to choose a file.

2. Write the data to that file.

Note that step 2 doesn't involve the JFileChooser in any way.
 
travis Haycock
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe a better question would be to how to approach this problem; What would be the most efficient way after this file is downloaded from Dropbox for the user to be able to decide where he/she wants to place the file in a friendly manner.
 
Paul Clapham
Sheriff
Posts: 21889
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have to pose the question after the download takes place? It would be more effective to ask before starting the download, so that you can stream the downloaded data directly to the file chosen by the user. If you don't do that then you have to store the downloaded data elsewhere and then copy it to the file chosen to the user, and that means you have to decide what "elsewhere" means.

By the way all of those "target path" variables in your existing code are probably irrelevant. The user is going to choose a path and you just write the data to that path.
 
travis Haycock
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do not specifically have to ask after the download has took place I was just looking at the code and thought it would have been the best way but obviously its not. Alright I will try and implement what you suggested with file chooser then, thanks.
 
Tim Moores
Saloon Keeper
Posts: 3261
54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I like to use java.awt.FileDialog rather than JFileChooser even in Swing apps, since it shows the OS-native dialog rather than the Swing dialog (with which users are likely to be less familiar).

Both have methods to set the directory that is shown when the dialog is opened, setDirectory and setCurrentDirectory, respectively. It's good practice to remember the last directory used, so that the dialog can show it the next time around.
 
travis Haycock
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the input Tim i'll try a block of code to see how it runs , thanks
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!