Please help me to compile this Java Program !!!

This Java Program when runs prompt users to enter a directory name and then the program lists the contents of the directory dir, including the contents of its subdirectories to any level of nesting through recursion.

However I'm having compilation errors. Heres the program

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

public class RecuDirList {

     public static void main(String[] args) {

     String directoryName; // Directory name entered by the user.
     File directory; // File object referring to the directory.

     TextIO.putln("Enter a directory name: ");
     directoryName = TextIO.getln().trim();
     directory = new File(directoryName);

     if (directory.isDirectory() == false) {
            // Program needs a directory name. Print an error message.
            if (directory.exists() == false) {
      TextIO.putln();
                TextIO.putln("There is no such directory!"); }
            else
                TextIO.putln("That file is not a directory.");
     }
     else {
              // List the contents of directory, with no indentation
             // at the top level.
             listContents( directory, "" );
    }

} // end main()


static void listContents(File dir, String indent) {
        // A recursive subroutine that lists the contents of
        // the directory dir, including the contents of its
        // subdirectories to any level of nesting.         
                  String[] files; // List of names of files in the directory.
        TextIO.putln(indent + "Directory \"" + dir.getName() + "\":");
        indent += " "; // Increase the indentation for listing the contents.
        files = dir.list();
        for (int i = 0; i < files.length; i++)
        {
              // If the file is a directory, list its contents
              // recursively. Otherwise, just print its name.
             File f = new File(dir, files);
             if (f.isDirectory())
                  listContents(f, indent);
             else
               TextIO.putln(indent + files); }
  } // end listContents()


} // end class RecuDirList

____________________________________________________________________________

When I compile I get the following errors

C:\java>javac RecuDirList.java
RecuDirList.java:11: cannot resolve symbol
symbol  : variable TextIO
location: class RecuDirList
     TextIO.putln("Enter a directory name: ");
     ^
RecuDirList.java:12: cannot resolve symbol
symbol  : variable TextIO
location: class RecuDirList
     directoryName = TextIO.getln().trim();
                     ^
RecuDirList.java:18: cannot resolve symbol
symbol  : variable TextIO
location: class RecuDirList
                                TextIO.putln();
                                ^
RecuDirList.java:19: cannot resolve symbol
symbol  : variable TextIO
location: class RecuDirList
                TextIO.putln("There is no such directory!"); }
                ^
RecuDirList.java:21: cannot resolve symbol
symbol  : variable TextIO
location: class RecuDirList
                TextIO.putln("That file is not a directory.");
                ^
RecuDirList.java:41: cannot resolve symbol
symbol  : variable TextIO
location: class RecuDirList
          TextIO.putln(indent + "Directory \"" + dir.getName() + "\":");
          ^
RecuDirList.java:48: cannot resolve symbol
symbol  : constructor File  (java.io.File,java.lang.String[])
location: class java.io.File
                 File f = new File(dir, files);
                          ^
RecuDirList.java:52: cannot resolve symbol
symbol  : variable TextIO
location: class RecuDirList
                   TextIO.putln(indent + files); }
                   ^
8 errors

What is it that causing "cannot resolve symbol variable TextIO"...???

I am using Windows XP and jdk1.3.1_04

THANKS
nickmcdonaldAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
schmidaConnect With a Mentor Commented:
Hi nick, the problem is that you try to use a class (TextIO) your compiler can t find. Why do you use TextIO for input and output? Where did you get the code

TextIO.putln()

from? Is it from a book or from the web? Maybe you can download this class from there and include (import) it into your program. This would solve your compilation errors. Another possibility would be to use the java standard to output test which is

System.out.println()

Here is your code without compilation errors:



import java.io.*;


public class RecuDirList {

     public static void main(String[] args) {

     String directoryName = ""; // Directory name entered by the user.
     File directory; // File object referring to the directory.

     System.out.println("Enter a directory name: ");
     try
      {
            directoryName = new BufferedReader(new InputStreamReader(System.in)).readLine().trim();
      }
      catch (Exception e)
      {
            System.out.println("Error:" + e.getMessage());
      }
     
     directory = new File(directoryName);

     if (directory.isDirectory() == false) {
            // Program needs a directory name. Print an error message.
            if (directory.exists() == false) {
     System.out.println("");
                System.out.println("There is no such directory!"); }
            else
            System.out.println("That file is not a directory.");
     }
     else {
              // List the contents of directory, with no indentation
             // at the top level.
             listContents( directory, "" );
    }

} // end main()


static void listContents(File dir, String indent) {
       // A recursive subroutine that lists the contents of
       // the directory dir, including the contents of its
       // subdirectories to any level of nesting.        
                  String[] files; // List of names of files in the directory.
      System.out.println(indent + "Directory \"" + dir.getName() + "\":");
       indent += " "; // Increase the indentation for listing the contents.
       files = dir.list();
       for (int i = 0; i < files.length; i++)
       {
            // If the file is a directory, list its contents
            // recursively. Otherwise, just print its name.
           File f = new File(dir, files[i]);
           if (f.isDirectory())
               listContents(f, indent);
           else
            System.out.println(indent + files[i]); }
  } // end listContents()


} // end class RecuDirList
0
 
nickmcdonaldAuthor Commented:
Please enlighten me with this compilation problem for this Java Program !!!!!
0
 
nickmcdonaldAuthor Commented:
THANKS A LOT, I GOT IT.

Nick
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.