?
Solved

Why isnt this program working? It did before!

Posted on 2003-03-14
10
Medium Priority
?
211 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month11 days, 16 hours left to enroll

752 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