| Extension | Description |
|---|---|
| .txt | text file |
| .java | Java source code file |
| .class | compiled Java bytecode file |
| .doc | Microsoft Word file |
| .xls | Microsoft Excel file |
| Adobe Portable Document File | |
| .mp3 | audio file |
| .jpg | image file |
| .zip | compressed archive |
| .html | hypertext markup language file (web page) |
| .exe | executable file |
import java.io.*; // for File
| Method | Description |
|---|---|
| canRead() | Whether or not this file exists and can be read |
| delete() | Deletes the given file |
| exists() | Whether or not this file exists on the system |
| getAbsolutePath() | The full path where this file is located |
| getName() | The name of the file as a string without directory attached |
| isDirectory() | Whether this file represents a directory/folder on the system |
| isFile() | Whether this file represents a file (nonfolder) on the system |
| length() | The number of characters in this file (size of file) |
| renameTo() | Changes this file's name to the given file's name |
PrintStream output = new PrintStream(new File("output.txt"));
Then instead of using System.out methods use the same like-named methods of the PrintStream class object
output.println("Hello world!");
Scanner input = new Scanner(new File("C:/My Documents/My Data/data.txt"));
Scanner input = new Scanner(new File("./data/hours.dat"));