• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

creating file in documents folder

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have tried and tried to find out how to do this but can't find any information on it. What I am wanting to do is create a file in the documents folder but since I am going to be giving the program out to family and friends and their file path is going to be different than mine I don't know how to go about writing it.

I know you use

to make the file bit I just don't know how to get it to make it in the documents folder.

I would also like to make it possible to use on linux machines since I have a few people I want to give it to using linux.

Here is my code I want to implement the code into:

 
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try using a JFileChooser.
when you call showSaveDialog(), it is automatically set for the Documents folder.
oh wait..my bad...you are trying to create it in code. not through the user
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure what the "documents" folder is. But anyway I'm with Randall, you should ask your users where they want the file put. Perhaps they use their "documents" folder for something else and don't want your application putting files there -- who knows?
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want a default path to start from, you could use the user.home System property (http://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html), then drill down from there. For example, to put it in a path under 'My Documents' you could do


The above code is pseudocode, so will likely need fixing. It uses (in addition to System properties) java.nio.file.Paths and java.nio.file.Path, both part of Java 7.
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't see how this can work across platforms. For e.g. on my Mac, there is no "My Documents" but "Documents". I do not think there is any universal property for (My) Documents like "user.home"
The only workaround I can think of is
Default to user.home
Let the user choose where to save.
Remember the last saved location (e.g. Using the preferences API)
Next time default to the last saved location.

 
Jason McKinley
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Steve Luke wrote:If you want a default path to start from, you could use the user.home System property (http://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html), then drill down from there. For example, to put it in a path under 'My Documents' you could do


The above code is pseudocode, so will likely need fixing. It uses (in addition to System properties) java.nio.file.Paths and java.nio.file.Path, both part of Java 7.



I have changed where I will be saving the information to the appdata/roaming folder. I used your code to do that but now my problem is how do I change it in my code:



I can't figure out how to exactly implement the new code into this part.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic