aspose file tools*
The moose likes Beginning Java and the fly likes File I/O Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "File I/O" Watch "File I/O" New topic
Author

File I/O

Lucky Singh
Ranch Hand

Joined: Jan 19, 2004
Posts: 125
Hi,
Following is a piece of some code which uses files.
My Java source and class files are in the bin directory.
C:/jdk/bin

I was able to compile the file successfully. How do I run the file? What should I type in at the prompt?

public static void main(String args[] )
{

Paice p = new Paice(args[2],args[3]);
String text;
StringTokenizer line = new StringTokenizer("");
String output ="";
String fileOut= args[1];
String fileIn = args[0];


try
{
FileWriter fw = new FileWriter(fileOut);
BufferedWriter bw = new BufferedWriter(fw);

FileReader fr = new FileReader(fileIn);
BufferedReader br = new BufferedReader(fr);
try
{
while ((text=br.readLine())!= null)
{
line= new StringTokenizer(text);
try
{
...

Thanks,
Lucky
[ April 01, 2005: Message edited by: Lucky Singh ]
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9046
    
  10
What is the name of your class?

You should type something like:

C:\jdk\bin>java MyClass filename1.txt filename2.txt firstArgYouNeedForPaiceConstructor secondArgYouNeedForPaiceConstructor
[ April 01, 2005: Message edited by: Marilyn de Queiroz ]

JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
The args array that is passed into main contains the arguments that are given from the command-line. Marilyn gives a good example of how this works. Typically each command-line argument is separated by white space. When you type "java MyClass" at the command-line, anything that follows is put into the args array. So if you do "java MyClass file1.txt file2.txt", then args[0] holds the string "file1.txt" and args[1] holds the string "file2.txt". That's really all there is to it.

Hopefully between Marilyn's example and my more general explanation, you can figure out what to do here. Let us know if you have any more questions.

Layne


Java API Documentation
The Java Tutorial
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
This looks an awful lot like this message, only the names have been changed to protect the guilty.
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9046
    
  10
[ April 01, 2005: Message edited by: Lucky Singh ]
Posts: 104 | Registered: Jan 2004


After 104 posts, Lucky, I'm surprised that you don't use code tags.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: File I/O