We help IT Professionals succeed at work.
Get Started

Please help me to compile this Java Program !!!

nickmcdonald
nickmcdonald asked
on
979 Views
Last Modified: 2012-06-22
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
Comment
Watch Question
Commented:
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE