Results 1 to 1 of 1
  1. #1
    Java Tip's Avatar
    Java Tip is offline Moderator
    Join Date
    Nov 2007
    Posts
    1,694
    Blog Entries
    430
    Rep Power
    9

    Default 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=&quot]String fileName = [/FONT][/COLOR][COLOR=#2a00ff][FONT=&quot]""[/FONT][/COLOR][COLOR=black][FONT=&quot];[/FONT][/COLOR]
      [COLOR=black][FONT=&quot]System.[/FONT][/COLOR][I][COLOR=#0000c0][FONT=&quot]out[/FONT][/COLOR][/I][COLOR=black][FONT=&quot].println([/FONT][/COLOR][COLOR=#2a00ff][FONT=&quot]"Please enter the file name: "[/FONT][/COLOR][COLOR=black][FONT=&quot]);[/FONT][/COLOR]
      [COLOR=black][FONT=&quot]BufferedReader br = [/FONT][/COLOR][B][COLOR=#7f0055][FONT=&quot]new[/FONT][/COLOR][/B][COLOR=black][FONT=&quot] BufferedReader([/FONT][/COLOR][B][COLOR=#7f0055][FONT=&quot]new[/FONT][/COLOR][/B][COLOR=black][FONT=&quot] InputStreamReader(System.[/FONT][/COLOR][I][COLOR=#0000c0][FONT=&quot]in[/FONT][/COLOR][/I][COLOR=black][FONT=&quot]));[/FONT][/COLOR]
      [COLOR=black][FONT=&quot]fileName = br.readLine();[/FONT][/COLOR]
      [COLOR=black][FONT=&quot]File file = [/FONT][/COLOR][B][COLOR=#7f0055][FONT=&quot]new[/FONT][/COLOR][/B][COLOR=black][FONT=&quot] File (fileName);[/FONT][/COLOR]
      
      [COLOR=black][FONT=&quot]System.[/FONT][/COLOR][I][COLOR=#0000c0][FONT=&quot]out[/FONT][/COLOR][/I][COLOR=black][FONT=&quot].println([/FONT][/COLOR][COLOR=#2a00ff][FONT=&quot]"Path: "[/FONT][/COLOR][COLOR=black][FONT=&quot] + file.getAbsolutePath());[/FONT][/COLOR]
      [COLOR=black][FONT=&quot]System.[/FONT][/COLOR][I][COLOR=#0000c0][FONT=&quot]out[/FONT][/COLOR][/I][COLOR=black][FONT=&quot].println([/FONT][/COLOR][COLOR=#2a00ff][FONT=&quot]"Last modified: "[/FONT][/COLOR][COLOR=black][FONT=&quot] + file.lastModified());[/FONT][/COLOR]
      [COLOR=black][FONT=&quot]System.[/FONT][/COLOR][I][COLOR=#0000c0][FONT=&quot]out[/FONT][/COLOR][/I][COLOR=black][FONT=&quot].println([/FONT][/COLOR][COLOR=#2a00ff][FONT=&quot]"Size in bytes: "[/FONT][/COLOR][COLOR=black][FONT=&quot] + file.length());[/FONT][/COLOR]
      [COLOR=black][FONT=&quot]System.[/FONT][/COLOR][I][COLOR=#0000c0][FONT=&quot]out[/FONT][/COLOR][/I][COLOR=black][FONT=&quot].println([/FONT][/COLOR][COLOR=#2a00ff][FONT=&quot]"Hidden: "[/FONT][/COLOR][COLOR=black][FONT=&quot] + file.isHidden());
    [/FONT][/COLOR]
    Last edited by Java Tip; 11-04-2007 at 06:01 PM.

Similar Threads

  1. How to read a text file from a Java Archive File
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-08-2008, 09:13 AM
  2. Converting text file(.txt) to JPG file(.jpg) in java
    By javadeveloper in forum Advanced Java
    Replies: 0
    Last Post: 11-09-2007, 04:22 PM
  3. Help with File in java
    By cachi in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 07:58 AM
  4. exe File Java
    By cachi in forum New To Java
    Replies: 1
    Last Post: 08-01-2007, 01:50 PM
  5. exe file with Java
    By Heather in forum New To Java
    Replies: 2
    Last Post: 07-03-2007, 04:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •