file search using java

codes of program for file search for m.s. dos

Page 1 of 1

4 Replies - 4894 Views - Last Post: 21 June 2009 - 07:58 PM Rate Topic: -----

#1 shany  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 15-June 09

file search using java

Post icon  Posted 19 June 2009 - 02:36 AM

import java.lang.*;
import java.io.*;
import java.util.*;

public class FileStatus {
public static void main(String[] argv){
// Ensure that a filename (or something) was given in argv[0]
if (argv.length == 0) {
System.err.println("Usage: Status filename");
System.exit(1);
}
for (int i = 0; i< argv.length; i++) {
status(argv[i]);
}
}
public static void status(String fileName) throws IOException {
System.out.println("---" + fileName + "---");
// Construct a File object for the given file.
File f = new File(fileName);
// See if it actually exists
if (!f.exists( )) {
System.out.println("file not found");
System.out.println( ); // Blank line
return;
}
// Print full name
System.out.println("Canonical name " + f.getCanonicalPath( ));
// Print parent directory if possible
String p = f.getParent( );
if (p != null) {
System.out.println("Parent directory: " + p);
}
// See if file, directory, or other. If file, print size.
if (f.isFile( )) {
// Report on the file's size
System.out.println("File size is " + f.length( ) + "bytes.");
} else if (f.isDirectory( )) {
System.out.println("It's a directory");
} else {
System.out.println("I dunno! Neither a file nor a directory!");
}
System.out.println( ); // blank line between entries
}
}

// i wanna know if this prog. is correct & i want to add more features for searchin files like hidden files,pictures, word sheet etc.

Is This A Good Question/Topic? 0
  • +

Replies To: file search using java

#2 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10437
  • View blog
  • Posts: 38,651
  • Joined: 27-December 08

Re: file search using java

Posted 19 June 2009 - 04:39 AM

Use BBCode when posting. For example:
Paste Your Code Here


Like so:

mport java.lang.*;
import java.io.*;
import java.util.*;

public class FileStatus {
public static void main(String[] argv){
// Ensure that a filename (or something) was given in argv[0]
if (argv.length == 0) {
System.err.println("Usage: Status filename");
System.exit(1);
}
for (int i = 0; i< argv.length; i++) {
status(argv[i]);
}
}
public static void status(String fileName) throws IOException {
System.out.println("---" + fileName + "---");
// Construct a File object for the given file.
File f = new File(fileName);
// See if it actually exists
if (!f.exists( )) {
System.out.println("file not found");
System.out.println( ); // Blank line
return;
}
// Print full name
System.out.println("Canonical name " + f.getCanonicalPath( ));
// Print parent directory if possible
String p = f.getParent( );
if (p != null) {
System.out.println("Parent directory: " + p);
}
// See if file, directory, or other. If file, print size.
if (f.isFile( )) {
// Report on the file's size
System.out.println("File size is " + f.length( ) + "bytes.");
} else if (f.isDirectory( )) {
System.out.println("It's a directory");
} else {
System.out.println("I dunno! Neither a file nor a directory!");
}
System.out.println( ); // blank line between entries
}
}




If you want to know if it is correct, run it and see the result.
In terms of adding more features, DIC will not give out code. We want to see a good faith effort on your part (even if it is just pseudo-code). If you run into trouble, well that's what we're here for. Good luck!
Was This Post Helpful? 0
  • +
  • -

#3 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8327
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: file search using java

Posted 19 June 2009 - 06:46 PM

And what is the question ?
Was This Post Helpful? 0
  • +
  • -

#4 tanah.melayu  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 5
  • View blog
  • Posts: 45
  • Joined: 21-February 09

Re: file search using java

Posted 21 June 2009 - 05:14 PM

View Postpbl, on 19 Jun, 2009 - 05:46 PM, said:

And what is the question ?


View Postshany, on 19 Jun, 2009 - 01:36 AM, said:

i wanna know if this prog. is correct & i want to add more features for searchin files like hidden files,pictures, word sheet etc


i guess... :blink:
Was This Post Helpful? 0
  • +
  • -

#5 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8327
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: file search using java

Posted 21 June 2009 - 07:58 PM

View Postshany, on 19 Jun, 2009 - 01:36 AM, said:

// i wanna know if this prog. is correct & i want to add more features for searchin files like hidden files,pictures, word sheet etc.

All of that at the same time or one at a time ? :D
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1