wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes Windows 7 Libraries JFileChooser HELP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Windows 7 Libraries JFileChooser HELP" Watch "Windows 7 Libraries JFileChooser HELP" New topic
Author

Windows 7 Libraries JFileChooser HELP

david eichel
Greenhorn

Joined: Dec 29, 2011
Posts: 5
Hi im writing a small application that requires me to enter in the name of a file in the JFileChooser of the swing class and save it. what its going to do is take that file name create a directory with the given name and create a file inside the directory and write the information to the file. i have already got all that worked out the problem is windows 7...the default open location for the JFileChooser is Documents...well documents happens to not be a physical folder but a library that points to multiple folders and so if i try and do something like this...

try and save the file hello to Documents this is what is returned with the getPath() method. C:\Users\David\Documents\hello
my program tries to create the folder hello inside the documents "folder" which of course is not a folder but a windows 7 library. the strange thing is that the mkdir() method returns true when it attempts to create the directory(C:\Users\David\Documents\hello)

here is my createDirectory method


so if i pass the value "C:\Users\David\Documents\hello into the method it prints this to the console

C:\Users\David\Documents
Creating directory hello
creation of directory successful
....but if i go into my documents library the directory is not there i have refreshed it and if i run the method again the result is the same...how can it be successful twice???

i did not clean it up yet so sorry but if you do not understand what my problem is just say so ill be happy to explain it the best i can.
google brings up almost nothing on this and i searched the forums for windows 7 libraries....and when you search google for anything that contains java and library the only thing you get is a bunch of libraries for java....i am stuck...


i should be able to save to a windows 7 library by getting the default save location for the library why cant i do this and why does it detect the library as a directory...
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19685
    
  20

On my Windows 7 machine, C:\Users\R.Spoor\Documents is a physical folder, and when I call your method from a little piece of test code it works as expected. Can you also show us the code that's showing the file chooser and calling this method?

And welcome to the Ranch!


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
david eichel
Greenhorn

Joined: Dec 29, 2011
Posts: 5
sure it is called from an actionlistener
bear in mind it is not clean as im still learning the language(2 semesters in)



and yes there is some redundant code in there but i was testing the results of the methods to see the differences in the console
and it may not be fully completed yet in terms of the end goal. what the method should do is get the file name to be saved and get the directory that was chosen.
for instance if i saved the file in documents then it would get the documents folder and then do a check to see if there is a subfolder with the same name as the filename so...
if(documents\filename.isDirectory()) then create a new file inside the filename folder
else{
//create the filename folder inside the documents folder and put the filename file inside the filename folder.
filename of course being the name of the file that was returned from the JFileChooser
documents\hello\hello.kbt for example

oh and thanks for welcoming me
david eichel
Greenhorn

Joined: Dec 29, 2011
Posts: 5
wait...ok i found the documents directory...my bad you are correct funny how when you goto the start menu and click documents it doesnt take you to the documents folder??? thats confusing anyways so when i hard code the directory into the file constructor it works
however when i pass it in with the actionlistener method it fails to create the directory...im going to do some more testing
david eichel
Greenhorn

Joined: Dec 29, 2011
Posts: 5
wow...ok its hit and miss...i pass the same parameter into it 3 times and it said it made the directory but it wasnt there so i ran it in debug mode to check out what was going on and it created the directory
david eichel
Greenhorn

Joined: Dec 29, 2011
Posts: 5
ok i found the problem i just have to debug it now...and sorry i didnt give you enough code to find out what was causing it ok so basicly its creating the directory and deleting it so fast that i cant see anything happen(which explains why i could see the directory only in the debugger). thank you for your help you've been awesome ill be coming back for more help if i need it in the future have a great day
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Windows 7 Libraries JFileChooser HELP