Improper Use of BufferedReader?

What is happening is that I want to open "shellscript.txt" and insert it into a new document then open another file and insert it in the same document right after where I insert "shellscript.txt". Maybe I am going about this the wrong way but what is happening is where the data in "shellscript.txt" is supposed to go, a line containing this is save:"java.io.BufferedReader@11a698a". What does that mean and how can I fix this? Here is the code and it compiles and runs error free.

import java.io.*;

public class TextIO2 {

public static void main(String args[]) { // We want to let the user specify which file we should open// on the command-line. E.g., 'java TextIO TextIO.java'.

if (args.length != 1) {

System.err.println("File Does Not Exist");

System.exit(1);

} // We're going to read lines from 'input', which will be attached// to a text-file opened for reading.

BufferedReader input = null;

try {

FileReader file = new FileReader(args[0]); // Open the file.

input = new BufferedReader(file); // Tie 'input' to this file.

} catch (FileNotFoundException x) { // The file may not exist.

System.err.println("File not found: " + args[0]);

System.exit(2);

}

// Now we read the file, line by line, echoing each line to

// the terminal.

try {

String line;

BufferedReader shellscript = new BufferedReader(new FileReader("shellscript.txt"));

FileWriter MyFile = new FileWriter("abcde.txt");

PrintWriter outFile = new PrintWriter(MyFile, true);

outFile.print(shellscript);

System.out.println(shellscript); // Temp for debugging purposes

while ((line = input.readLine()) != null) {

System.out.println(line);// Temp for debugging purposes

outFile.println(line);

}

MyFile.close();

outFile.close();

} catch (IOException x) {

x.printStackTrace();

}

}

}

[1998 byte] By [adh2k1] at [2007-9-30 11:44:54]
# 1

The code is writing a string representation of the BufferedReader object to the file. See the API for Object.toString() method at http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html#toString() for more information. (Java make a hidden conversion from the object to a string representation of the object when you try to write an object in this manner. There are ways to write an object, but that's another matter and isn't what you intended - the code is incorrect.)

Take a look at this simple example from Sun's The Java Tutorial that reads a file and writes a copy of the file. By studying it you should be able to easily expand it to read a second file and then write a copy of it following the earlier copy.

http://java.sun.com/docs/books/tutorial/essential/io/filestreams.html

ChuckBing at 2007-7-4 13:15:08 > top of Java-index,Administration Tools,Sun Connection...