Getting a Proper URL from a File Object : File « File « Java Tutorial

Home
Java Tutorial
1.Language
2.Data Type
3.Operators
4.Statement Control
5.Class Definition
6.Development
7.Reflection
8.Regular Expressions
9.Collections
10.Thread
11.File
12.Generics
13.I18N
14.Swing
15.Swing Event
16.2D Graphics
17.SWT
18.SWT 2D Graphics
19.Network
20.Database
21.Hibernate
22.JPA
23.JSP
24.JSTL
25.Servlet
26.Web Services SOA
27.EJB3
28.Spring
29.PDF
30.Email
31.J2ME
32.J2EE Application
33.XML
34.Design Pattern
35.Log
36.Security
37.Apache Common
38.Ant
39.JUnit
Java Tutorial » File » File 
11.2.41.Getting a Proper URL from a File ObjectPrevious/Next
import java.io.*;
import java.net.*;

public class FileURL {
  public static void main(String args[]) throws MalformedURLException {
    File file = new File("The End");
    URL url2 = file.toURI().toURL();
    System.out.printf("Good url %s%n", url2);
  }
}
11.2.File
11.2.1.The File Class
11.2.2.Testing and Checking File Objects: file name and path
11.2.3.Providing a URI for a remote file
11.2.4.isAbsolute(): Returns true if the File object refers to an absolute pathname, and false otherwise.
11.2.5.getParent(): Returns the name of the parent directory of the file or directory represented
11.2.6.getParentFile(): Returns the parent directory as a File object, or null if this File object does not have a parent.
11.2.7.toString(): Returns a String representation of the current File object
11.2.8.exists(): Returns true if it exists and false otherwise
11.2.9.isDirectory(): Returns true if it is an existing directory and false otherwise
11.2.10.isFile(): Returns true if it is an existing file and false otherwise
11.2.11.isHidden(): Returns true if it is hidden and false otherwise
11.2.12.canRead(): Returns true if you are permitted to read the file and false otherwise.
11.2.13.canWrite(): Returns true if you are permitted to write to the file and false otherwise.
11.2.14.getAbsolutePath(): Returns the absolute path for the directory or file referenced by the current File object
11.2.15.getAbsoluteFile(): Returns a File object containing the absolute path for the directory or file referenced by the current File object.
11.2.16.list(): Returns a string array containing the children files and directories
11.2.17.listFiles(): Returns a File array containing the children files and directories
11.2.18.length(): Returns the length of current file in long
11.2.19.Create a human-readable file size
11.2.20.lastModified(): Returns last modified time in milliseconds since midnight on 1st January 1970 GMT
11.2.21.renameTo(File path): Rename a file or directory
11.2.22.setReadOnly(): Sets the file as read-only and returns true if the operation is successful
11.2.23.Filtering a File List
11.2.24.mkdir(): Creates a directory
11.2.25.mkdirs(): Creates a directory including any parent directories
11.2.26.createNewFile(): Creates a new empty file
11.2.27.createTempFile(String prefix, String suffix, File directory): a static method that creates a temporary file
11.2.28.delete(): delete the file or directory
11.2.29.Display File class constants and test some methods
11.2.30.deleteOnExit(): delete file or directory when the program ends
11.2.31.File Class Enhancements
11.2.32.Creates a file and sets it to read-only.
11.2.33.Create a file and change its attribute to readonly
11.2.34.List all roots
11.2.35.Get the free space
11.2.36.Get the usable space
11.2.37.Get the total space
11.2.38.Set file attributes.
11.2.39.Change a file attribute to writable
11.2.40.Change a file attribute to read only
11.2.41.Getting a Proper URL from a File Object
11.2.42.Get icon for file type
11.2.43.Get all xml files by file extension
11.2.44.Get file extension name
11.2.45.File.getCanonicalFile() converts a filename path to a unique canonical form suitable for comparisons.
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.