Set JFileChooser current dir to remote dir - jfilechooser

I have to set current dir in JFileChooser to remote dir(windows share), but it doesn't work.
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(new File("\\\\192.168.11.11"));
chooser.showSaveDialog(null);
I found this bug description: http://bugs.sun.com/view_bug.do;jsessionid=ad25b2513da86b421875051509357?bug_id=6741919, but it isn't fixed yet.
Is it any way to work it around(I can't map that dir)?

If you set the file path in the constructor like so:
fc=new JFileChooser("\\\\10.16.7.139\\ErrorLogs");
it works fine, although it seems like you can't open the root of the server. If I removed the \ErrorLogs portion of the string it didn't work.

Related

Error converting Java.io.File to org.core.resource.IFile?

I am dynamically creating a File in the workspace and trying to generate a IFile instance of it.
IPath location= Path.fromOSString(file.getAbsolutePath());
IFile iFile=ResourcesPlugin.getWorkspace().getRoot().getFile(location);
FileEditorInput input = new FileEditorInput(iFile);
but when I try to see if ifile exists or not (using iFile.exists()) it gives false.
I tried using canonical path as well but that also did not help.
Changes to the file system are not automatically detected by the Eclipse workspace, you'll need to tell the workspace to refresh its view of the local file system. You can do this with:
iFile.refreshLocal(IResource.DEPTH_ZERO, null);
If more than one file has changed you can do the refresh at the folder level changing the depth.

an error 3013 thrown when writing a file Adobe AIR

I'm trying to write/create a JSON file from a AIR app, I'm trying not so show a 'Save as' dialogue box.
Here's the code I'm using:
var fileDetails:Object = CreativeMakerJSX.getFileDetails();
var fileName:String = String(fileDetails.data.filename);
var path:String = String(fileDetails.data.path);
var f:File = File.userDirectory.resolvePath( path );
var stream:FileStream = new FileStream();
stream.open(f, FileMode.WRITE );
stream.writeUTFBytes( jsonToExport );
stream.close();
The problem I'm having is that I get a 'Error 3013. File or directory in use'. The directory/path is gathered from a Creative Suite Extension I'm building, this path is the same as the FLA being developed in CS that the Extension is being used with.
So I'm not sure if the problem is that there are already files in the directory I'm writing the JSON file to?
Do I need to add a timer in order to close the stream after a slight delay, giving some time to writing the file?
Can you set up some trace() commands? I would need to know what the values of the String variables are, and the f.url.
Can you read from the file that you are trying to write to, or does nothing work?
Where is CreativeMakerJSX.getFileDetails() coming from? Is it giving you data about a file that is in use?
And from Googling around, this seems like it may be a bug. Try setting up a listener for when you are finished, if you have had the file open previously.
I re-wrote how the file was written, no longer running into this issue.

I can't get netbeans to find a txt file I have in the same directory... java.io.FileNotFoundException

I can't make it path specific because once I get this program to work (this is the last thing I have to do) I'm uploading to my university's ilearn website and it has to run on my professors computer with no modifications. I've tried a few different amalgamations of code similar to the following...
File file = new File("DataFile.txt");
Scanner document = new Scanner(new File("DataFile.txt"));
Or...
java.io.File file = new java.io.File("DataFile.txt");
Scanner document = new Scanner(file);
But nothing seems to work. I've got the necessary stuff imported. I've tried moving DataFile around in a few different folders (the src folder, and other random folders in the project's NetBeansProjects folder) I tried creating a folder in the project and putting the file in that folder and trying to use some kind of
documents/DataFile.txt
bit I found online (I named the folder documents).
I've tried renaming the file, saving it in different ways. I'm all out of ideas.
The file is just a list of numbers that are used in generating random data for this program we got assigned for building a gas station simulator. The program runs great when I just use user input from the console. But I can not get netbeans to find that file for the life of me! Help!?!?!?
Try adding the file to build path ..
public void readTextFile (){
try{
Scanner scFile =new Scanner(new File("filename.txt");
while(scFile.hasNext()){
String line =scFile.nextLine();
Scanner details=new Scanner(line).useDelimiter("symbol");
than you can work from there to store integer values use e.g in an array
litterArr(size)=details.nextInt();
Note: size is a variable counting the size/number of info the array has.
}
scFile.close();
{
catch
(FILENOTFOUNDEXCEPION e){
..... *code*
}
Keep file in the same folder as the program,but if it is saved in another folder you need to supply the path indicating the location of the file as part of the file name e.g memAthletics.Lines.LoadFromFile('C:\MyFiles\Athletics.txt');
hope this helps clear the problem up :)

Resolving relative paths outside the standard directories (applicationDirectory, desktopDirectory, etc)

I need to navigate to a file relative to my applicationDirectory, but as it says in the documentation:
No ".." reference that reaches the file system root or the application-persistent storage root passes that node; it is ignored.
But the crazy thing is that if I do something like
File.applicationDirectory.resolvePath("/home/myHome/");
I can get anywhere in the filesystem.
My question is:
is there a workaround to navigate from my applicationDirectory to a relative path like "../../my.cfg" ?? (I need to read a config file generated by a different application)
if you are trying to access root privileged folders - than you can not.
in other cases try do next "home/blah/blah/blah/../../my.cfg" and research once again http://help.adobe.com/en_US/AIR/1.5/jslr/flash/filesystem/File.html to save your time about navigation.
also you have another few ways: create a link to your file or run external bash/bat script.
I was previously using the little hack mentioned in Eugene's answer to copy from an absolute path:
var file = 'C:\Users\User1\Pictures\pic.png';
var newPath = air.File.applicationStorageDirectory.resolvePath('images/pic.png');
air.File.applicationDirectory.resolvePath('/../../../../../../../../../../' +
file).copyTo(newPath, true);
However, this is a much better way of doing it:
var file = 'C:\Users\User1\Pictures\pic.png';
var newPath = air.File.applicationStorageDirectory.resolvePath('images/pic.png');
new air.File(file).copyTo(newPath, true);

Initializing JFileChooser with a non-existing directory

In our installation program I want to enable users to use install directory which, obviously, does not exist yet. I want that when the Browse button is pressed, a JFileChooser dialog will be opened, and will be initialized with the currently selected directory. However, setCurrentDirectory only works with existing directories, and setSelectedFile only seems to work when not working with DIRECTORIES_ONLY like I do.
Is there any way around this?
Thanks,
splintor
This is the (partial) solution I found. It is good enough for me:
JFileChooser fc = new JFileChooser(initialExistingDirectory);
FileChooserUI fileChooserUI = fc.getUI();
if (fileChooserUI instanceof BasicFileChooserUI)
{
BasicFileChooserUI basicFileChooserUI = (BasicFileChooserUI) fileChooserUI;
basicFileChooserUI.setFileName(initialNonExistingDirectory);
}