Handling files

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sandesh964
    New Member
    • Jan 2007
    • 10

    #1

    Handling files

    can anyone tell me how to write a program to find the list of filenames in a directory specified by user

    how to copy the contents of a source file into destination file with each word of source file reversed
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by sandesh964
    can anyone tell me how to write a program to find the list of filenames in a directory specified by user

    how to copy the contents of a source file into destination file with each word of source file reversed
    Changed thread title.

    Maybe you should read a files tutorial before you try to write the program.

    Comment

    • sateesht
      New Member
      • Apr 2007
      • 41

      #3
      Hi,
      Below is the code to list the contents of a specified Direcory:

      Code:
       import java.io.*; 
       
      public class FileRead
      {
      	public static void main(String[] args) throws IOException 
      	{
      BuffererReader br=new BuferedReader(new InputStreamReader(System.in));
      System.out.println("Enter the Directory name")	
      	 File f=new File(br.readLine());
      		File[] f1=f.listFiles();
      		for(int i=0;i<f1.length;i++)
      		{
      			if(!f1[i].isFile()){
      		System.out.println("Files inside the "+ f1[i]+ "Directory");
      				File[] f2=f1[i].listFiles();
      				for(int j=0;j<f2.length;j++)
      					System.out.println(f2[j]);
      				}else
      					System.out.println(f1[i]);
      	}
      }
      }
      Cheers,
      Sateesh
      Last edited by r035198x; Apr 20 '07, 07:25 AM. Reason: added code tags

      Comment

      Working...