I am trying to read input from a text file(read only numbers in arraylist). My text file looks like this containing numbers(146,7,-1,-2,3).It looks like this actually: HEADER 1467-1-23
Now,when I put HEADER string in the file,my code would not read the first number which is 146 in my case and starts with the second number "7".However,when the string HEADER is not there,146 is also read which is obviously what I want.My code is this:
String pathToWrite="C:\\Users\\User\\Desktop\\Hello.txt";
FileReader fr=new FileReader(pathToWrite);
BufferedReader bufferedReader=new BufferedReader(fr);
String aLine=null;
int numberOfLine=0;
List<Integer> list = new ArrayList<Integer>();
List<Integer> list2 = new ArrayList<Integer>();
while((aLine=bufferedReader.readLine()) != null )
{
if(numberOfLine > 1) //since header lies in first line,I want to skip that line
{
list.add(Integer.parseInt(aLine));
}
numberOfLine++;
}
Want suggestions about how I can change the code to read the first number too? Thanks in advance
1467-1-23number - How do you make out that146is one number and 7 is another. Is the format fixed? For ex, I can say146is actually 3 numbers -1,4and6.