Results 1 to 2 of 2
  1. #1
    XDrew574X is offline Member
    Join Date
    Mar 2011
    Rep Power

    Default Searching directories for folders and .txt files

    I need some help with the coding that I have, please.

    I have to tell the console which directory I want to search in,
    I have to search the directory for .txt files,
    then I have to search the .txt for the words "I am a lawyer in * who has to find a lawyer overseas."

    I am so lost. This is the coding I have so far. Can anyone please guide me??
    Thanks in advance!

    import java.util.Scanner;

    * @author Melly
    public class Main {

    public static void main(String[] args) throws FileNotFoundException, IOException {
    String s;

    System.out.println("Starting Directory: ");
    Scanner kb = new Scanner(;
    s = kb.nextLine();

    File f;
    f = new File(s); // Looks for files in a directory
    System.out.println("Is directory? " + f.isDirectory());

    private static void search(File f) throws FileNotFoundException, IOException {
    File[] allFiles = f.listFiles();
    for (File ff : allFiles) {
    if (ff.isDirectory()) {
    } else {



    private static void searchfortext(File f) throws FileNotFoundException, IOException {
    DataInputStream kb = new DataInputStream(new DataInputStream(new FileInputStream(f.getPath())));
    String h = DataInputStream.readUTF(kb);

    FileFilter fileFilter = new FileFilter() {

    public boolean accept(File pathname) {
    return true; // or false


  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power


    Your post is the same as your previous post from 3/26:

    Probably the reason you didn't get help then is that you didn't ask a specific question but rather a very broad and general statement "I am so lost. This is the coding I have so far. Can anyone please guide me?", one that isn't readily answerable.

    If you want a better chance of getting help, I suggest you try to solve each problem one at a time in separate very small programs, programs that do nothing but try to solve the single problem at hand.

    For instance, first create a small program that tries to get information from the user to see which directory to search in, and then print the input out. Next create a small program that has the directory hard-coded in (to simplify it) and does nothing but tries to search a given directory for all .txt files, and then prints out the list. Last create another very small program that have to searches these text files for the words "I am a lawyer in * who has to find a lawyer overseas." When/if you get stuck at a specific step, please let us know, post any debug attempts too, and any error messages. The better your question, the more likely you'll get a helpful answer. Also, please read my signature link below on how to use code tags, for if your code is easier to read, more will likely read it and help you.


Similar Threads

  1. java searching from many files
    By manish250 in forum Advanced Java
    Replies: 0
    Last Post: 12-31-2010, 07:50 AM
  2. Save files in directories
    By Tota in forum New To Java
    Replies: 2
    Last Post: 09-02-2010, 02:49 PM
  3. List of files and directories.
    By artemff in forum CLDC and MIDP
    Replies: 6
    Last Post: 01-02-2010, 04:06 PM
  4. Replies: 4
    Last Post: 10-10-2009, 12:26 AM
  5. Replies: 20
    Last Post: 12-17-2007, 03:20 PM

Tags for this Thread

Posting Permissions

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