This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Having some problem with FileDialog 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 "Having some problem with FileDialog " Watch "Having some problem with FileDialog " New topic
Author

Having some problem with FileDialog

vamsi naki
Ranch Hand

Joined: May 18, 2011
Posts: 46
Hi ,
I wrote a porgam where there is a textarea and two buttons ,one to load files into the textarea and other button to save what is written in the text area.
I have two problems though
1)The methods filedialog.getDirectory(),filedialog.getFile() return nulll so i am not able to load any file in the text area
2)When i try to save a file ,i used filedialog.setDirectory("C:"+"\" ") and filedialog.setFile("untitled.txt").The problem is it doesnt show the c:\ as the default directory when the dialog box opens .


Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

vamsi naki wrote:2)When i try to save a file ,i used filedialog.setDirectory("C:"+"\" ")


In other words, you set the directory to this string:



But you really wanted this string, right?



So you've just got your Java string escaping rules a bit mixed up. You need this code:

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Having some problem with FileDialog