Opening a specific directory using JFileChooser.
Iam using JFIleChooser to select a file is there any way that i the dialog opens at a particular directory say...c:\gallery\imagee...the default dialog opens @ MyDocuments Folder.
Read the API documentation of the class, especially coustructor section.
Similar Messages
-
Unable to open a Zip directory using windows default uncomressed folder
Hi
I Created a zip directory in AIX using java.util.zipfile. now when I am trying to open it in windows using its defult uncompress method I am unable to do it.
here is the sample code
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
public class Zipdita {
public void zipFolder(String srcFolder, String destZipFile, String Z_PATH) throws Exception {
ZipOutputStream zip = null;
FileOutputStream fileWriter = null;
fileWriter = new FileOutputStream(destZipFile);
zip = new ZipOutputStream(fileWriter);
addFolderToZip(Z_PATH, srcFolder, zip);
zip.flush();
zip.close();
public void addFileToZip(String path, String srcFile, ZipOutputStream zip)
System.out.println("file in addFileToZip " + srcFile);
try {
File folder = new File(srcFile);
/*if (folder.isDirectory()) {
addFolderToZip(path, srcFile, zip);
} else {*/
byte[] buf = new byte[1024];
int len;
FileInputStream in = new FileInputStream(srcFile);
zip.putNextEntry(new ZipEntry(srcFile ));
while ((len = in.read(buf)) > 0) {
zip.write(buf, 0, len);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
public void addFolderToZip(String Z_PATH, String srcFolder, ZipOutputStream zip)
throws Exception {
File folder = new File(srcFolder);
System.out.println("Folder Name::"+folder.getName());
for (String fileName : folder.list()) {
//if (path.equals("")) {
System.out.println("Filename to be zipped" + fileName);
addFileToZip(Z_PATH, srcFolder + fileName, zip);
//} else {
//addFileToZip(path + "/" + folder.getName(), srcFolder + "/" + fileName, zip);
the srcFolder referes to /a/b/
destZipfile refres to /a/b.zip
srcfile refers to /a/b/c.txt
now the zip gets created but it takes the path /a/b.Due to which I m unable to open it in windows.
please help me in removing the / from the Zip file.Hello and welcome to the forum. Let me add code tags to your posted code
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
public class Zipdita {
public void zipFolder(String srcFolder, String destZipFile, String Z_PATH) throws Exception {
ZipOutputStream zip = null;
FileOutputStream fileWriter = null;
fileWriter = new FileOutputStream(destZipFile);
zip = new ZipOutputStream(fileWriter);
addFolderToZip(Z_PATH, srcFolder, zip);
zip.flush();
zip.close();
public void addFileToZip(String path, String srcFile, ZipOutputStream zip)
System.out.println("file in addFileToZip " + srcFile);
try {
File folder = new File(srcFile);
/*if (folder.isDirectory()) {
addFolderToZip(path, srcFile, zip);
} else {*/
byte[] buf = new byte[1024];
int len;
FileInputStream in = new FileInputStream(srcFile);
zip.putNextEntry(new ZipEntry(srcFile ));
while ((len = in.read(buf)) 0) {
zip.write(buf, 0, len);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
public void addFolderToZip(String Z_PATH, String srcFolder, ZipOutputStream zip)
throws Exception {
File folder = new File(srcFolder);
System.out.println("Folder Name::"+folder.getName());
for (String fileName : folder.list()) {
//if (path.equals("")) {
System.out.println("Filename to be zipped" + fileName);
addFileToZip(Z_PATH, srcFolder + fileName, zip);
//} else {
//addFileToZip(path + "/" + folder.getName(), srcFolder + "/" + fileName, zip);
} -
Saving a PDF to a specific directory - using a shortcut
We work with various applications that create PDF's and then we need to save them to one of several locations on a server. When you click on Save As (Shift+ctrl+s) you open a dialog box and then must drill for your directory. Is there a way to create a shortcut in this space as you can do in Windows? We could then list our favorites and avoid all the drilling we have to do every time we save.
If it always opens to the same default folder, just place a shortcut there
and then double-click it when the Save As dialog opens...
On Fri, Aug 8, 2014 at 6:14 AM, Robertlopez <[email protected]> -
Is there a way to open up a directory for static files.
Is there a way to open a specific directory or set of directories up for browsing with WLS 8.1.5 (such as having static .txt,.html files,etc..) without having to deploy some sort of java app to do this.
Basically we need a quick and dirty way to access files sitting on a specific directory on our Web Server machine. Example is there a way to open up just the directory /home/user/files/video for access?
Thanks,
Cash ChitwoodWell in order to host something I can't see you doing it without having to have a web application? So if you do not have a web application you will probably need to do that and deploy the war I guess even if its an empty war. In which case you can set that parameter I posted about earlier to access your folder?
-Jesus -
Open files from a specific directory
Dear all,
I have the following source code that simply selects files from a directory.
private void openFile()
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(
JFileChooser.FILES_ONLY );
int result = fileChooser.showOpenDialog( this );
// user clicked Cancel button on dialog
if (result == JFileChooser.CANCEL_OPTION )
return;
File filename = fileChooser.getSelectedFile();
if (filename == null || filename.getName().equals( "" ))
JOptionPane.showMessageDialog( this,
"Invalid File Name",
"Invalid File Name", JOptionPane.ERROR_MESSAGE );
else
// open the file
try
// Open an input stream
FileInputStream fin1 = new FileInputStream(filename);
// Read and print a line of text
BufferedReader d1 = new BufferedReader(new InputStreamReader(fin1));
abs = d1.readLine();
outputArea1.setText("");
outputArea1.append(abs + "\n\n");
outputArea1.setCaretPosition(0);
// Close our input and output stream
fin1.close();
catch (IOException e5) {
JOptionPane.showMessageDialog(this, "Error Opening File", "Error", JOptionPane.ERROR_MESSAGE);
} // end catch
} // end else
} // end private
My question is: Can I force it to open files from a specific directory, and NOT from MyDocuments directory????
thanks,
vxc\r = return
\n = linefeed
\j = illegal escape character
JFileChooser fileChooser = new JFileChooser("C:\j2sdk1.4.2\bin");
You could/should use:
(new File).pathSeparator
or
(new File).pathSeparatorChar
and
(new File).separator
or
(new File).separatorChar
http://java.sun.com/j2se/1.4.1/docs/api/java/io/File.html -
Save file without JFileChooser in specific directory
hi!
can you save a file without opening a JFileChooser dialogue to a specific directory??
the problem I have got is not how to address to the directory but how to save the file....
could someone help me please?
thx
charlyIf u only want to save the file instead of selecting from the filechooser then you should use
JFileChooser fc = new JFileChooser();
int retVal = fc.showSaveDialog(frame);
if(retVal == JFileChooser.APPROVE_OPTION)
String filename = fc.getSelectedFile().getName();
getName() will give file name and getAbsolutePath() will give the full path.
filename -> is the file name that u entered for saving in the field. I am not sure if this what u wanted. Hope this helps otherwise pls be more specific in ur question.
Selvi.
I was pondering the same question. if I just open the
dialog, instead of choosing a file from a directory, I
want to type in a new file name, and save it.
help is appreciated. -
Problem using JFileChooser to select a destination directory
If you set JFileChooser to DIRECTORIES_ONLY, a user has to single click on the desired directory and click on the approveButton. This works just fine - you get the user's desired directory using getSelectedFile().
e.g. /home/joeuser/docs
But if the user double-clicks on their desired directory (a common user practice), the directory is opened AND the directory name is stuck in the File Name: field. If they now click on the approveButton, the returned selected directory is the user's desired directory PLUS the name of the directory again. Not what the user intended.
e.g. /home/joeuser/docs/docs
Now, when you keep the File Name: field from being filled in when the user double-clicks on a directory, you have encounter another problem. The approveButton will not activate unless there is something in the File Name: field!
Does anybody have a solution for the approveButton working with an empty File Name: field?
Thanks,
ScottI had the same problem. Gave up with JFileChooser and made a directory chooser that only display the diectory structure in a JTree and no file stuff at all.
Source: http://www.msticky.freeserve.co.uk/JDialog_directoryChooser.java
to use it; String selectedDirPath=JDialog_directoryChooser.choose(stringTitle, stringInitialSelectedPath)
returns the selected directory path or null if none selected.
To make it work alone you'll need to remove my RRException class. If you want to see it in use first download noname.jar from http://www.msticky.freeserve.co.uk
ps. my site needs testing
thanks, sticky -
How can I use automator to open terminal change directory run a python script?
Hi all,
I dont really ever use automator - which may be my big problem - and I am trying to make an apllication that seems fairly simple in theroy. I want something that will lunch terminal, cd to the place where my python script lives and then run it. I have tried a number of suggested ways and can get the terminal to open and the directory to change but cant figure out how to run the script. This is my workflow if i did it manually each time
- open terminal
- type cd "the place where my file lives"
- type python uploadr.py -d
I can get terminal to open then cd to the right place but cant get the "python uploadr.py -d" to run without an error.
any help would be very appricated
thanks!!!
Jthis is the script I got closest with - I know its something to do with breaking those two commands up but i just dont know how to do it
on run {input, parameters}
tell application "Terminal"
activate
if (the (count of the window) = 0) or ¬
(the busy of window 1 = true) then
tell application "System Events"
keystroke "n" using command down
end tell
end if
do script "cd /Users/behole/Desktop/FlickrUpload/" & "python uploadr.py -d" in window 1
end tell
return input
end run
this is the error I get in terminal after I run it
Last login: Mon Jul 23 15:37:17 on ttys000
be-holes-MacBook-Pro:~ behole$ cd /Users/behole/Desktop/FlickrUpload/python uploadr.py -d
-bash: cd: /Users/behole/Desktop/FlickrUpload/python: No such file or directory
be-holes-MacBook-Pro:~ behole$ -
Get the file directory/location using JFileChooser
Dear,
How to get the file directory and it location with using JFilechooser after select the indicate file?
ThanksThere is an example at the top of JFileChooser's doc.
http://java.sun.com/j2se/1.4.1/docs/api/javax/swing/JFileChooser.html -
Using JFileChooser to select directory only
Hi. I am using JFileChooser to let the user to select the directory to save some files into the user-selected directory. I set the JFileChooser to show only directory and not files. Below show part of my code:
private JFileChooser chooser = new JFileChooser();
chooser.setFileHidingEnabled(true);
chooser.setMultiSelectionEnabled(false);
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
chooser.setDialogType(JFileChooser.OPEN_DIALOG);
int state = chooser.showDialog(frame, "Select Directory");
if (state == JFileChooser.APPROVE_OPTION )
file = chooser.getCurrentDirectory();
However, the File reference that i get is not the user-selected directory. Please help.
Thank you.Hi,
i found that if user writes in the text field of save dialog name of the file(but application needs directory), getCurrentDirectory() returns correct directory. but if user chooses directory, getCurrentDirectory() returns parent directory but getSelectedFile() returns correct one, so i suggest something like this(it's nasty but it works [i hope;])
JFileChooser dirChooser = new JFileChooser("");
dirChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
if (dirChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION)
java.io.File curDir = dirChooser.getSelectedFile().isDirectory()?dirChooser.getSelectedFile():dirChooser.getCurrentDirectory(); -
Can use RBAC for grant privilege to user on specific directory or not?
If I want user "aaa:group1" to have write privilege on specific directory of user "bbb:group2" (such as /export/home/bbb).
Can I use RBAC Feature for this case? How to?
Because basic permission of Unix very large scope (user, group, other).
If I specific folder "/export/home/bbb" to rwxrwxr-x, then change group of user "aaa" to group2. Other user in group2 will have write privilege too.
Thank you.If you want fine grain control over directory permissions than the feature you want are access control lists (acl's).
Try man setfacl, though I warn you that the documentation for acl's are pretty confusing... -
How to open a specific Calendar in Outlook
Hi,
I'm struggling to find an example on other forums, or not understanding the code.
I want to open a non-default calendar in Outlook to create an appointment (it's a hotmail account, which is shared with a couple of people, so that they can all see the same appointment in outlook).
The account is in the form of "[email protected]". I've tried 3 different examples I've found on forums and none work. Here's the code that works for the default calendar, so I'm after the code to open the specific calendar (the
variable passed as strCalendar).
Public Function fnCreateOutlookAppointment(strStartDate As String, Optional strEndDate As String, Optional strEventTitle As String, Optional strLocation As String, Optional strDetails As String, Optional intDuration As Integer, Optional strStartTime As String,
Optional strEmailList As String, Optional strStatus As String, Optional strAction As String, Optional blnAllDay As Boolean, Optional intReminderTime As Integer, Optional strCalendar As String)
Dim olApp As New outlook.Application
Dim olAppointment As AppointmentItem
Dim myRequiredAttendee As outlook.Recipient
Set olAppointment = olApp.CreateItem(olAppointmentItem)
If Len(strStartTime) < 1 Then
strStartTime = "09:00:00"
End If
If blnAllDay = Null Then
blnAllDay = False
End If
If Len(strEndDate) < 1 Then
strEndDate = strStartDate
End If
With olAppointment
.Start = DateValue(strStartDate) + TimeValue(strStartTime)
.Duration = intDuration
.Subject = strEventTitle
.Location = strLocation
.Body = strDetails
Select Case strStatus
Case "Free"
.BusyStatus = olFree
Case Else
.BusyStatus = olBusy
End Select
Select Case blnAllDay
Case True
.AllDayEvent = True
Case Else
.AllDayEvent = False
End Select
.ReminderMinutesBeforeStart = intReminderTime
.ReminderSet = True
If Len(strEmailList) > 0 Then 'only add if email addresses supplied (and using ; as a break e.g. "[email protected];[email protected]"
Set myRequiredAttendee = .Recipients.Add(strEmailList)
myRequiredAttendee.Type = olRequired
End If
If strAction = "save" Then
.Save
Else
.Display
End If
End With
Set olAppointment = Nothing
Set olApp = Nothing
End Function
_________________________________________________________ Every day is a school day!Hi ChrisJC,
To get the specific calendar folder (non-default folder), please refer to this code below:
Dim oNS As Outlook.NameSpace
Dim MyItemsFolder As Outlook.MAPIFolder
Dim myAppoint As Outlook.AppointmentItem
Set oNS = oApp.GetNamespace("MAPI")
Set MyItemsFolder = oNS.Folders("[email protected]").Folders.Item("Calendar")
Then you could add appointment item by using
Items.Add method.
Set myAppoint = MyItemsFolder.Items.Add(olAppointmentItem)
Regards
Starain
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
How to Open a Specific Folder in the Finder via Shortcut Key
I'm sure this has been covered elsewhere, so sorry for not finding it...
Is it possible to assign a shortcut key to open a specific folder with Automator or AppleScript? There are 4-5 commonly used folders buried 10-11 levels deep on a server and I'd love to have a shortcut key to open those particular folders in the Finder.
Could you give me some assistance?
Thanks!QuickKeys may work, or you can look on http://www.versiontracker.com or http://www.macupdate.com for other alternatives.
Another option is to create aliases to those folders and store the aliases in a local folder which you can place on your Dock, the Finder window sidebar or toolbar. -
How to open a specific file in projector.
Hi to all
can any body tells me that how to open a specific file in
projector with an application not in browser????
and also want to add a button to mute the sound just like in
intros with fade in and out effect.
its urgent....
Thanks in advanceHi,
You can use FlashJester JStart
http://jstart.flashjester.com
that will open up any file the has been associated in Window
Explorer.
Download a FREE evaluation copy and try it for yourself.
Please look at the example files given.
Regards
FlashJester Support Team
e. - [email protected]
w. -
http://www.flashjester.com
There is a very fine line between "hobby" and
"mental illness." -
Open a Specific browser from an applet
We can open a browser using appletContext().showDocument() Or even using Runtime.getRuntime().exec(rundll32,url.dll,FileProtocolHandler),
but how can i specify a specific browser in applet. I have an application which works only in IE.You can't open a specific browser (if the applet is unsigned), and what's the problem with showDocument()?
The need for this is unclear to me.
Maybe you are looking for
-
In the last week or two when I try to import media into FCP X I end up with a very dark and locked import screen. The only way I can recover is to force quit FCP X. It doesn't always happen but it is getting more and more frequent. I have not updat
-
Cancel accrual of Rebate Agreement
Hi My client has a requirement. He wants to cancel accruals for a rebate agreement because the accruals were done by mistake. He wants to cancel accruals and delete the rebate agreement. I read somewhere that it can be done by deleting the condition
-
TextField.PHONENUMBER cannot access phone book in samsung.
Below is the line I use to look up phone number from the Contact List. g_txtDestination = new TextField("Destination:", "", 20, TextField.PHONENUMBER); So far, it works on Nokia, Sony Ericsson and Motorola. But it does not work in samsung. Why ? Is t
-
Spotlight trouble indexing mail in Lion
Having a terrible time with Spotlight perpetually indexing mail. system log shows Jul 11 17:01:26 xxxxx com.apple.mdworker.lsb.0[2660]: [Assigning new unique identifiers to all messages] Jul 11 17:01:26: --- last message repeated 249 times --- and of
-
Bluetooth and listening to music
I'm having intermittent problems with my iPhone restarting music play after I receive a call via Bluetooth while in my car. This issue only occurs when I'm connected via Bluetooth. For example, while listening to music via my iPhone in my car, a call