I have been looking for an answer to this question, but haven't found any solutions.
Basically, I am trying to print ONLY the Working Directory under which the file in question is. Eg. if the file is in "C:\Users\user\Desktop\folder", I would want it to print out only "folder".
Is there any way to do this avoiding trimming the path string?
Here is a section of my code, in case someone needs it.
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(new java.io.File("."));
chooser.setDialogTitle("Choose a folder to rename the elements");
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
chooser.setAcceptAllFileFilterUsed(false);
if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION)
out.println("Directory: " + chooser.getSelectedFile());
I am trying to choose a file and print out the folder (not the absolute path) in which it is located.
Any help is much appreciated.