Link to home
Start Free TrialLog in
Avatar of jgilmour
jgilmour

asked on

Why isnt this program working? It did before!

Hey all, i was using this program like a month ago, and i go to compile it and im getting errors... Here is the code...
-- cut RemoveAttacks.java --
import java.io.*;
import java.util.*;
import java.awt.*;


class RemoveAttacks {

 public static void main(String[] args) {

   if (argv.length != 3) {    
    System.err.println ("Usage: java RemoveAttacks <weblogfile> <outputfile>");
    System.exit (1); }

  try {

       System.out.println( "Where is the weblog located?" );
       System.out.println( "ex. c:\\windows\\system32\\weblog\\weblog32.txt" );
       System.out.print( "File Location: " );
        weblog = ITPInput.readLine();
       System.out.println( "What would you like the edited/stripped file name to be?" );
       System.out.print( "New File Name: " );
        newfile = ITPInput.readLine();
       
       File origFile = new File(weblog);
       BufferedReader reader = new BufferedReader(
           new FileReader(origFile));  

       File tempFile = new File(newfile);  
       PrintWriter writer = new PrintWriter(
           new FileWriter(tempFile));

       for(String line; (line = reader.readLine()) != null; ) {
         if (line.indexOf("cmd") != -1) {
           System.out.println(line); // Used
            writer.println(line); }
         }
       
       writer.close();
       reader.close();
          }
        catch(java.io.IOException e){
         System.out.println("Cannot access file");
     }
    }
}

-- end cut --

I'm getting weird errors like the argv.length, which im positive worked before along with everything else...

-- start errors --
D:\j2sdk1.4.1_02\bin>javac Removeattacks.java
Removeattacks.java:10: cannot resolve symbol
symbol  : variable argv
location: class RemoveAttacks
   if (argv.length != 3) {
       ^
Removeattacks.java:19: cannot resolve symbol
symbol  : variable weblog
location: class RemoveAttacks
        weblog = ITPInput.readLine();
        ^
Removeattacks.java:19: cannot resolve symbol
symbol  : variable ITPInput
location: class RemoveAttacks
        weblog = ITPInput.readLine();
                 ^
Removeattacks.java:22: cannot resolve symbol
symbol  : variable newfile
location: class RemoveAttacks
        newfile = ITPInput.readLine();
        ^
Removeattacks.java:22: cannot resolve symbol
symbol  : variable ITPInput
location: class RemoveAttacks
        newfile = ITPInput.readLine();
                  ^
Removeattacks.java:24: cannot resolve symbol
symbol  : variable weblog
location: class RemoveAttacks
       File origFile = new File(weblog);
                                ^
Removeattacks.java:28: cannot resolve symbol
symbol  : variable newfile
location: class RemoveAttacks
       File tempFile = new File(newfile);
                                ^
7 errors

-- end cut --

Any help would be greatly appreciated!
ASKER CERTIFIED SOLUTION
Avatar of yongsing
yongsing

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of yongsing
yongsing

What is "ITPInput"? The following won't compile because "ITPInput" is undefined:

ITPInput.readLine();
Avatar of TimYates
The reason it won't compile now, is that someone changed it so it doesn't compile ;-)
>> The reason it won't compile now, is that someone changed it so it doesn't compile ;-)  

So my advice is: If it ain't broke, don't fix it!
1.
>> if ( argv.length != 3 ) {    

Make it: if ( args.length != 3 ) {

2. Declare the variables 'weblog' and 'newfile' as strings:

String weblog, newfile ;

3. There should also be a catch statement for a FileNotFound exception (you might get this error after fixing the previous ones). Or else, just replace IOException by Exception in the catch statement.

Nothing else as such.

Mayank.
>> There should also be a catch statement for a FileNotFound exception

FileNotFoundException is a subclass of IOException, and he is already catching IOExceptions.
All right :-)

Mayank.
jgilmour:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

- Points to yongsing

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

girionis
EE Cleanup Volunteer