Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Why isnt this program working? It did before!

Posted on 2003-03-14
10
Medium Priority
?
213 Views
Last Modified: 2010-03-31
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!
0
Comment
Question by:jgilmour
9 Comments
 
LVL 9

Accepted Solution

by:
yongsing earned 800 total points
ID: 8136538
I fixed the problems. "argv" should be "args". You also need to declare "newfile" and "weblog" as Strings.

import java.io.*;
import java.util.*;
import java.awt.*;


class RemoveAttacks {

public static void main(String[] args) {

  if (args.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: " );
      String weblog = ITPInput.readLine();
      System.out.println( "What would you like the edited/stripped file name to be?" );
      System.out.print( "New File Name: " );
      String 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");
    }
   }
}
0
 
LVL 9

Expert Comment

by:yongsing
ID: 8136615
What is "ITPInput"? The following won't compile because "ITPInput" is undefined:

ITPInput.readLine();
0
 
LVL 35

Expert Comment

by:TimYates
ID: 8136619
The reason it won't compile now, is that someone changed it so it doesn't compile ;-)
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 9

Expert Comment

by:yongsing
ID: 8136638
>> 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!
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 8136671
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.
0
 
LVL 9

Expert Comment

by:yongsing
ID: 8136694
>> There should also be a catch statement for a FileNotFound exception

FileNotFoundException is a subclass of IOException, and he is already catching IOExceptions.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 8149660
All right :-)

Mayank.
0
 

Expert Comment

by:CleanupPing
ID: 9058690
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.
0
 
LVL 35

Expert Comment

by:girionis
ID: 9762826
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
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Don’ts and Dos are two important end products of software testing basics that a tester needs to regard. This article attempts to explain the principles of both.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses
Course of the Month10 days, 10 hours left to enroll

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question