Command Line Args in Eclipse

From: Wade (wade_at_wadesmart.com)
Date: 11/04/04


Date: 4 Nov 2004 05:22:22 -0800

11042004 0715 GMT-6

I have only recently been using Eclipse to learn Java. One of my
exercises needs a command line argument. I read one of the posts about
where to find the argument however Im still not understanding how to do
this.

The exercise takes a file and concerts all the letts to AllCaps. Using
command line Im instructed to type: java AllCapsDemo TempFile.java

On the Eclipse Arguments tap I see two sections: Program and VM args. I
typed the name of a file in the program section and the produced an
error. In the VM section I get a different error, Exception in thread
'main'.

Both of these sections have a button named Variables. This brings up a
window with a string of choices. I have tried several choices but each
one provides a different error.

This is the code for the exercise:

import java.io.*;

public class AllCapsDemo {
public static void main(String[] args) {
AllCaps cap = new AllCaps(args[0]);
cap.convert();
}
}

class AllCaps {
String sourceName;

AllCaps(String sourceArg) {
sourceName = sourceArg;
}

void convert() {
try {
// create file objects
File source = new File(sourceName);
File temp = new File("cap" + sourceName + ".tmp");

// create input stream
FileReader fr = new FileReader(source);
BufferedReader in = new BufferedReader(fr);

// create output stream
FileWriter fw = new FileWriter(temp);
BufferedWriter out = new BufferedWriter(fw);

boolean eof = false;
int inChar = 0;
do {
inChar = in.read();
if (inChar != -1) {
char outChar = Character.toUpperCase( (char)inChar );
out.write(outChar);
} else
eof = true;
} while (!eof);
in.close();
out.close();

boolean deleted = source.delete();
if (deleted)
temp.renameTo(source);
} catch (IOException e) {
System.out.println("Error == " + e.toString());
} catch (SecurityException se) {
System.out.println("Error == " + se.toString());
}
}
}

Question: Would someone tell me how to do this? Advise me as to what I
am doing wrong. Thank you.

Wade


Quantcast