To do list
This project will record an event which will be described by Title, Description, Date, Time. The events will be stored and retrieved from a text file called events.txt. The program should read a file at a start and should store and delete new and already present events from text file. This program should find events with respect to date as well as name. All search event description should be displayed.
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class TextDisplay
{
static void modifyFile(String filePath, String oldString, String newString)
{
File fileToBeModified = new File(filePath);
String oldContent = "";
BufferedReader reader = null;
FileWriter writer = null;
try
{
reader = new BufferedReader(new FileReader(fileToBeModified));
//Reading files
String line = reader.readLine();
//display text data
try {
while ((line = reader.readLine()) != null){
System.out.println(line);
}
} catch (IOException e1) {
e1.printStackTrace();
}
while (line != null)
{
oldContent = oldContent + line + System.lineSeparator();
line = reader.readLine();
}
//replacing old data
String newContent = oldContent.replaceAll(oldString, newString);
//rewriting
writer = new FileWriter(fileToBeModified);
writer.write(newContent);
}
catch (IOException e)
{
e.printStackTrace();
}
finally
{
try
{
//Closing the resources
reader.close();
writer.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
public static void main(String[] args)
{
modifyFile("E:/Testing/Student.txt", "85", "95");
System.out.println("done");
}
}
Comments
Leave a comment