import java.io.*;
import java.util.*;
import javax.swing.*;
import java.util.StringTokenizer;
public class Sample {
public static int count = 0;
public static String s[]=new String[2];
public static String s2;
public static String s3;
public static void main (String args[]) throws IOException{
isRead();
}
public static  void isRead()throws IOException{
int count2 = 0;
BufferedReader lnr = new BufferedReader (new FileReader("subjects.txt"));
String line;
String ask;

while ((line = lnr.readLine())!=null){
StringTokenizer st = new StringTokenizer(line);
s[count2] = st.nextToken();
count2++;
}
isInput();
}
public static void isInput() throws IOException{
FileWriter writer = new FileWriter("output.txt");
int i;
String ask = JOptionPane.showInputDialog("Enter.");
if(ask.equals(s[0])){
StringTokenizer st = new StringTokenizer(ask,s[0],true);
while(st.hasMoreTokens()){
String ask2 = st.nextToken();
if(ask2.equals("1")){
i = Integer.parseInt(ask2);
}
else if(ask2.equals("M")){
s2 = "Math17";
}

}
String semester = "\n1\n";
writer.write(semester+s2);
writer.flush();
writer.close();
isInput();
}
else if(ask.equals(s[1])){
StringTokenizer st = new StringTokenizer(ask,s[1],true);
while(st.hasMoreTokens()){
String ask2 = st.nextToken();
if(ask2.equals("2")){
i = Integer.parseInt(ask2);
}
else if(ask2.equals("I")){
s3 = "IT110";
}

}
String semester = "\n1\n";
writer.write(semester+s3);
writer.flush();
writer.close();
}

}

and my subjects.txt:
(1,Math17)
(2,IT110)

Please help me on how to fix this. It only writes the last one, which is IT110, and no Math17 appears. Was the first one that i write was saved? Or everytime i write a new one, the old one will be deleted..I hope you can help me. Thank you.

You need to explain what you are trying to accomplish and how because your code doesn't make any sense

Do you have something personal against the code tags that after our repeated attempts to get you start using them, you still don't.

As far as the programs goes, my comments could be copy-pasted from those of javaAddict.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.