Solved

Email Client/Server App. - FileName

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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.

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now