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
Solved

Email Client/Server App. - FileName

Posted on 2004-04-21
5
154 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
  • 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

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…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…

808 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