(C++)The problem I have is changing the contents of a text file and having those
ID: 3681589 • Letter: #
Question
(C++)The problem I have is changing the contents of a text file and having those changed results being put into another text file. I already have the code to read the first text file line by line and the code that will change the strings in the way I want, but how do i combine them and then output it correctly to said different File. The first part of the question is me asking how do you get my string changing code to change the text file line by line (followed by it then being outputed to said different file).
Explanation / Answer
This is the code to tranfer contents of one file to another file line by line. Hope it will help you.
import java.io.*;
class Transfer{
public static void main(String args[]){
try{
FileInputStream fstream = new FileInputStream("file1.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
FileOutputStream fstream1 = new FileOutputStream("file2.txt");
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fstream1));
String line;
while ((line = br.readLine()) != null) {
bw.write(line);
bw.newLine();
}
br.close();
bw.close();
} catch(Exception e)
{System.out.println(e);
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.