Solved

Email Client/Server App. - FileName

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
thymeleaf natural templating vs JSP 2 98
windows explorer path to command prompt 5 44
expectj telnet failing 5 36
tomcat administrtor 12 47
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

770 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