|
-
Jul 12th, 2001, 11:33 AM
#1
Thread Starter
Hyperactive Member
Help with printing to file..
Okay, below is my code, it is supposed to (btw this is for a class project in case you are wondering why any one would want to do this) okay, it is supposed to take in a file and replace all the letters of one type with another.
So far as I can tell it reads in the file well, and then it parses it
into a vector with the appropriate text strings
But when I try to write out to a file, then it simply makes the file name but writes nothing to it.
If any one can help I would appreciate it.
public static void fileReplaceCopy(String readFrom, String writeTo,
char toReplace, char replaceWith){
try{
Vector v = new Vector();
FileReader myFile;
BufferedReader inputFile = null;
String line;
PrintWriter out =
new PrintWriter(new BufferedWriter( new FileWriter(writeTo)));
myFile = new FileReader(readFrom);
inputFile = new BufferedReader(myFile);
while( (line = inputFile.readLine()) != null){
v.addElement(line.replace(toReplace,replaceWith));
}
int i = 0;
while (v.elementAt(i) != null){
System.out.println(v.elementAt(i));
out.println (v.elementAt(i));
i ++;
}
out.close();
myFile.close();
}
catch (Exception e){}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|