Solved

Email Client/Server App. - FileName

Posted on 2004-04-21
5
157 Views
Last Modified: 2010-03-31
i have an array of user entered file paths that i store in files[]
then when i want to send i do the following...
 
 File f = new File(files[i]);
 
How do i get the name of the file now from f ?

Thanks

0
Comment
Question by:tricks801
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 92

Accepted Solution

by:
objects earned 400 total points
ID: 10884547
String name = f.getName();
0
 

Author Comment

by:tricks801
ID: 10884561
thanks
0
 
LVL 92

Expert Comment

by:objects
ID: 10884591
have a look at the the javadoc for any otyher methods your require:

eg.

 File getAbsoluteFile()
          Returns the absolute form of this abstract pathname.
 String getAbsolutePath()
          Returns the absolute pathname string of this abstract pathname.
 File getCanonicalFile()
          Returns the canonical form of this abstract pathname.
 String getCanonicalPath()
          Returns the canonical pathname string of this abstract pathname.
 String getName()
          Returns the name of the file or directory denoted by this abstract pathname.
 String getParent()
          Returns the pathname string of this abstract pathname's parent, or null if this pathname does not name a parent directory.
 File getParentFile()
          Returns the abstract pathname of this abstract pathname's parent, or null if this pathname does not name a parent directory.
 String getPath()
          Converts this abstract pathname into a pathname string.
0
 
LVL 23

Assisted Solution

by:rama_krishna580
rama_krishna580 earned 100 total points
ID: 10884784
f.getAbsoluteFile()
f.getAbsolutePath()
f.getCanonicalFile()
f.getCanonicalPath()
f.getName()
f.getParent()
f.getParentFile()
f.getPath() ............etc......

......here is the example code you can use it...........to find out the details...

                        System.out.println();
                        System.out.println("*************************************************************");

                        System.out.println("getName()          = " + f.getName());
                        System.out.println("getAbsoluteFile().getName() = " + f.getAbsoluteFile().getName());

                        boolean exists = f.exists();
                        if(exists)
                              System.out.println("Exists()           = " + exists);
                        else
                              System.out.println("Does not exists()           = " + exists);


                        if (!exists) { System.exit(1);  }

                        System.out.println("canRead()          = " + f.canRead());
                        System.out.println("canWrite()         = " + f.canWrite());
                        System.out.println("getPath()          = " + f.getPath());
                        System.out.println("getAbsolutePath()  = " + f.getAbsolutePath());
                        System.out.println("getCanonicalPath() = " + f.getCanonicalPath());
                        System.out.println("getAbsoluteFile()  = " + f.getAbsoluteFile());
                        
                        // External Usage Options
                        //System.out.println("toURL()            = " + f.toURL());
                        //System.out.println("toURI()            = " + f.toURI());

                        System.out.println("getParent()        = " + f.getParent());
                        System.out.println("isAbsolute()       = " + f.isAbsolute());

                        boolean isDirectory = f.isDirectory();
                        if(isDirectory)
                              System.out.println("isDirectory()      = " + isDirectory);
                        else
                              System.out.println("isNotDirectory()   = " + isDirectory);
                        
                        boolean isFile = f.isFile();
                        if(isFile)
                              System.out.println("isFile()           = " + isFile);
                        else
                              System.out.println("isNotFile()        = " + isFile);

                        System.out.println("isHidden()         = " + f.isHidden());
                        System.out.println("lastModified()     = " + (d = f.lastModified()) + " = " + new Date(d));
                        System.out.println("length()           = " + f.length());

                        if (isDirectory)
                        {
                              String[] subfiles = f.list();
                              
                              for (int i=0; i < subfiles.length; i++)
                              {
                                    System.out.println("File in this Dir   = " + subfiles[i] );
                              }
                        }

                        System.out.println("*************************************************************");
                        System.out.println();
0
 
LVL 92

Expert Comment

by:objects
ID: 10894569
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

687 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question