A workaround would be
int ixSep = name.indexOf(File.pathSepa
if (ixSep > -1) {
name = name.subtring(++ixSep);
}
Main Topics
Browse All TopicsI am suprised with the getName method in File
in Windows it gives the complete name eg : C:\Docum ,...\...\fileName
but in Linux it gives what I want the fileName
for eg:
String name =tempFile.getName();
Windows : Gives the complete Path
Linux :Gives me the Name
How do I make it to work the same for Windows and Linux
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Hey CEHJ ...what a coincidence ...it is a part of the code that you helped me with :-)
String[] filePaths = inputFiles.split(",");
String decideType =filePaths[0].toUpperCase(
String[] fileNames = new String[filePaths.length];
if(decideType.endsWith("CE
{
for(int i = 0;i < filePaths.length;i++) {
File tempFile = new File(filePaths[i]);
fileNames[i] = tempFile.getName();
System.out.println("This is the fileName\n"+fileNames[i]);
}
}
Sorry I forgot that ....will keep that in mind
// Gets the file string from the user seperated by commas ( for eg: if
// the user submits 2 files then the String would be
// /home/john/file1,/home/joh
String[] filePaths = inputFiles.split(",");
String[] fileNames = new String[filePaths.length];
for(int i = 0;i < filePaths.length;i++) {
File tempFile = new File(filePaths[i]); // Creates the file with the complete path
fileNames[i] = tempFile.getName(); // extracts the name
System.out.println("This is the fileName\n"+fileNames[i]);
}
For Linux
o/p is
file1
file2
For Woindows it is
C:\Documents and Settings\indukuri\Desktop\
C:\Documents and Settings\indukuri\Desktop\
Thanks
I cannot reproduce what you are seeing.. can you see if this program below runs as expected? If it does, then there is something else to research..
-Matt
import java.io.File;
public class FileTest {
public static void main(String[] args) {
// Gets the file string from the user seperated by commas ( for eg: if
// the user submits 2 files then the String would be
// /home/john/file1,/home/joh
String inputFiles = args[0];
String[] filePaths = inputFiles.split(",");
String[] fileNames = new String[filePaths.length];
for(int i = 0;i < filePaths.length;i++) {
File tempFile = new File(filePaths[i]); // Creates the file with the complete path
fileNames[i] = tempFile.getName(); // extracts the name
System.out.println("This is the fileName\n"+fileNames[i]);
}
}
}
Business Accounts
Answer for Membership
by: CEHJPosted on 2005-09-14 at 13:05:06ID: 14884329
That is odd. These are the docs:
"Returns the name of the file or directory denoted by this abstract pathname. This is just the last name in the pathname's name sequence. If the pathname's name sequence is empty, then the empty string is returned."
Can you post the code?