-
Exploring java.io.File
The program prompts the user to enter the filename from console and makes a File object of that file. Then different properties of the file are printed on the console.
Code:
[COLOR=black][FONT="]String fileName = [/FONT][/COLOR][COLOR=#2a00ff][FONT="]""[/FONT][/COLOR][COLOR=black][FONT="];[/FONT][/COLOR]
[COLOR=black][FONT="]System.[/FONT][/COLOR][I][COLOR=#0000c0][FONT="]out[/FONT][/COLOR][/I][COLOR=black][FONT="].println([/FONT][/COLOR][COLOR=#2a00ff][FONT="]"Please enter the file name: "[/FONT][/COLOR][COLOR=black][FONT="]);[/FONT][/COLOR]
[COLOR=black][FONT="]BufferedReader br = [/FONT][/COLOR][B][COLOR=#7f0055][FONT="]new[/FONT][/COLOR][/B][COLOR=black][FONT="] BufferedReader([/FONT][/COLOR][B][COLOR=#7f0055][FONT="]new[/FONT][/COLOR][/B][COLOR=black][FONT="] InputStreamReader(System.[/FONT][/COLOR][I][COLOR=#0000c0][FONT="]in[/FONT][/COLOR][/I][COLOR=black][FONT="]));[/FONT][/COLOR]
[COLOR=black][FONT="]fileName = br.readLine();[/FONT][/COLOR]
[COLOR=black][FONT="]File file = [/FONT][/COLOR][B][COLOR=#7f0055][FONT="]new[/FONT][/COLOR][/B][COLOR=black][FONT="] File (fileName);[/FONT][/COLOR]
[COLOR=black][FONT="]System.[/FONT][/COLOR][I][COLOR=#0000c0][FONT="]out[/FONT][/COLOR][/I][COLOR=black][FONT="].println([/FONT][/COLOR][COLOR=#2a00ff][FONT="]"Path: "[/FONT][/COLOR][COLOR=black][FONT="] + file.getAbsolutePath());[/FONT][/COLOR]
[COLOR=black][FONT="]System.[/FONT][/COLOR][I][COLOR=#0000c0][FONT="]out[/FONT][/COLOR][/I][COLOR=black][FONT="].println([/FONT][/COLOR][COLOR=#2a00ff][FONT="]"Last modified: "[/FONT][/COLOR][COLOR=black][FONT="] + file.lastModified());[/FONT][/COLOR]
[COLOR=black][FONT="]System.[/FONT][/COLOR][I][COLOR=#0000c0][FONT="]out[/FONT][/COLOR][/I][COLOR=black][FONT="].println([/FONT][/COLOR][COLOR=#2a00ff][FONT="]"Size in bytes: "[/FONT][/COLOR][COLOR=black][FONT="] + file.length());[/FONT][/COLOR]
[COLOR=black][FONT="]System.[/FONT][/COLOR][I][COLOR=#0000c0][FONT="]out[/FONT][/COLOR][/I][COLOR=black][FONT="].println([/FONT][/COLOR][COLOR=#2a00ff][FONT="]"Hidden: "[/FONT][/COLOR][COLOR=black][FONT="] + file.isHidden());
[/FONT][/COLOR]