Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Email Client/Server App. - FileName

Posted on 2004-04-21
5
Medium Priority
?
159 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 1600 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 400 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

610 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