I've written the folowing code (using the ArraySet class ive created which is sort of like an array with extra methods): when I use the first time the filereader there is no problem, but the time I use the second one on it reads the first line and keeps printing.
Ive tried using only the second filereader puting a break at the end of the while, etc. and nothing has worked to stop it.
Please help!
import java.io.*;
import java.util.*;
public class DriverEjercicio 2{
public static void main(String [] args){
System.out.prin tln("Nombre del archivo: ");
Scanner sc = new Scanner(System. in);
String nombreArchivo = sc.nextLine();
String linea;
ArraySet<String > naturales = new ArraySet<String >(50);
ArraySet<String > pares = new ArraySet<String >(50);
try{
BufferedReader filein = new BufferedReader (new FileReader
(nombreArchivo) );
while((linea = filein.readLine ()) != null) {
System.out.prin tln(linea);
Scanner st = new Scanner(linea);
String num = st.next();
naturales.add(n um);
}
filein.close();
}
catch(FileNotFo undException fnfe){
System.err.prin tln(fnfe);
}
catch(IOExcepti on ioe){
System.err.prin tln(ioe);
}
System.out.prin tln("\nNombre del archivo: ");
nombreArchivo = sc.nextLine();*/
try{
BufferedReader f = new BufferedReader (new FileReader
(nombreArchivo) );
while((linea = f.readLine()) != null) {
System.out.prin tln(linea);
Scanner st = new Scanner(linea);
String num = st.next();
pares.add(num);
}
f.close();
}
catch(FileNotFo undException fnfe){
System.err.prin tln(fnfe);
}
catch(IOExcepti on ioe){
System.err.prin tln(ioe);
}
}
}
Ive tried using only the second filereader puting a break at the end of the while, etc. and nothing has worked to stop it.
Please help!
import java.io.*;
import java.util.*;
public class DriverEjercicio 2{
public static void main(String [] args){
System.out.prin tln("Nombre del archivo: ");
Scanner sc = new Scanner(System. in);
String nombreArchivo = sc.nextLine();
String linea;
ArraySet<String > naturales = new ArraySet<String >(50);
ArraySet<String > pares = new ArraySet<String >(50);
try{
BufferedReader filein = new BufferedReader (new FileReader
(nombreArchivo) );
while((linea = filein.readLine ()) != null) {
System.out.prin tln(linea);
Scanner st = new Scanner(linea);
String num = st.next();
naturales.add(n um);
}
filein.close();
}
catch(FileNotFo undException fnfe){
System.err.prin tln(fnfe);
}
catch(IOExcepti on ioe){
System.err.prin tln(ioe);
}
System.out.prin tln("\nNombre del archivo: ");
nombreArchivo = sc.nextLine();*/
try{
BufferedReader f = new BufferedReader (new FileReader
(nombreArchivo) );
while((linea = f.readLine()) != null) {
System.out.prin tln(linea);
Scanner st = new Scanner(linea);
String num = st.next();
pares.add(num);
}
f.close();
}
catch(FileNotFo undException fnfe){
System.err.prin tln(fnfe);
}
catch(IOExcepti on ioe){
System.err.prin tln(ioe);
}
}
}
Comment