Maestus Maestus - 8 months ago 50
Java Question

Control a particular line from a text file in java

Hi im wrote a function but theres a problem with that.Function should do if the new string's id same with old strings id the function should return false but when the second string wont allowed whether ids same or not...

public boolean WriteOnTxt() throws IOException {
boolean durum =false;
FileReader fr = new FileReader("HastaKayit.txt");
BufferedReader br = new BufferedReader(fr);
String line;
String[] parcala;

while ((line = br.readLine()) != null) {
line = br.readLine();
parcala = line.split("#");

if (parcala[0].equals(this.getPatientID())) {
durum = true;
} else {
durum = false;
return durum;


You're skipping lines:

while ((line = br.readLine()) != null) { line = br.readLine();

This section assigns a String to line twice so effectively only running your loop on every other line of data. To fix it, remove the second line = br.readLine();