Results 1 to 1 of 1
Thread: Exploring java.io.File
-
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.
Java 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]
Last edited by Java Tip; 11-04-2007 at 06:01 PM.
Similar Threads
-
How to read a text file from a Java Archive File
By Java Tip in forum Java TipReplies: 0Last Post: 02-08-2008, 09:13 AM -
Converting text file(.txt) to JPG file(.jpg) in java
By javadeveloper in forum Advanced JavaReplies: 0Last Post: 11-09-2007, 04:22 PM -
Help with File in java
By cachi in forum New To JavaReplies: 1Last Post: 08-07-2007, 07:58 AM -
exe File Java
By cachi in forum New To JavaReplies: 1Last Post: 08-01-2007, 01:50 PM -
exe file with Java
By Heather in forum New To JavaReplies: 2Last Post: 07-03-2007, 04:54 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks