Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // class Student
- import java.io.*;
- public class Student implements Serializable
- {
- // instance variables
- private int studentId;
- private String name;
- /**
- * Constructor for objects of class Student
- */
- public Student(int id, String name)
- {
- this.name = name;
- studentId = id;
- }
- public String getName()
- {
- return name;
- }
- public void setName(String newName)
- {
- name = newName;
- }
- public void setId(int newId)
- {
- studentId = newId;
- }
- public int getId()
- {
- return studentId;
- }
- }
- import java.io.BufferedReader;
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.io.Writer;
- public class Demo{
- public static void main(String[] argv)
- throws Exception{
- Writer output = new BufferedWriter(new FileWriter("fixed.txt"));
- BufferedReader freader =
- new BufferedReader(new FileReader("orinal.txt"));
- String s;
- while ((s=freader.readLine())!=null){
- String tokens[] = s.split(",");
- String id = f[0];
- String name = f[1];
- // check against the ID or ID's you don't want. If the current ID is not the one
- // you don't want then write it to the output file
- if (!id.equals("00001") {
- output.write(s + "n");
- }
- }
- freader.close();
- output.close();
- }
- }
- public void writeToStudentFile(int idToIgnore)
- {
- try{
- writer = new BufferedWriter(new FileWriter(studentFile, true));
- Iterator it = students.iterator();
- while (it.hasNext())
- {
- Student s = (Student)it.next();
- if (s.getId() != idToIgnore)
- {
- writer.write(s.getId() + "," + s.getName() + "n");
- }
- }
- writer.flush();
- writer.close();
- }
- catch(IOException e){System.out.println(e);}
- }
Add Comment
Please, Sign In to add comment