Menu



Java program for file content modifier


FileContentModifier.java

import java.io.*;
class FileContentModifier
{
public static void main(String[] args) throws IOException
{
BufferedReader br = new BufferedReader(new FileReader("note2.txt"));
FileWriter fw = null;
StringBuilder fileContent = new StringBuilder();
String resultContent = null;
// read a line and store
while ( br.ready() )
{
fileContent.append(br.readLine());
fileContent.append("\n"); // after every line append, goes to next line
}
resultContent = fileContent.toString().replace("welcome", "hello");
fw = new FileWriter("note2.txt");
fw.write(resultContent);
System.out.println("File modified successfully!");
br.close();
fw.close();
}
}

note2.txt

welcome to studentstutorial.com











Connection failed: SQLSTATE[28000] [1045] Access denied for user 'studentdb'@'localhost' (using password: YES)

Subscribe