This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
    Bookmark Topic Watch Topic
  • New Topic

how to read two numbers at a time as input from a text file in java  RSS feed

 
priyanka kusuma
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi guys, I just need to know how to take two numbers at a time as input from text file as i have to check whether these two numbers are present in the array or not
my input file contains two numbers per line separated with " " i.e,
1 2
2 3
4 5.............
i hope you people reply as soon as possible because i am stuck with this and with out completing this part of code i cannot go further please
 
Tony Docherty
Bartender
Posts: 3205
78
  • Mark post as helpful
  • send pies
  • Report post to moderator
There are plenty of tutorials on how to read a file line by line so I assume you are only stuck on how to split the line. You can split the line using the String classes split() method and then convert each substring to a number or you could use a java.util.Scanner to get the numbers from the line.
 
priyanka kusuma
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hey Tony is this what you are asking me to do
FileInputStream file = new FileInputStream("E:/clusters.txt");
Scanner inputFile = new Scanner(file);
String line = inputFile.nextLine( );
final String[] array = line.split(" ");
what i need is after splitting it will take one number at a time but i need to take two numbers at a time as i have to compare them with the existing array list if you dont mind can you clearly correct the code where i have written wrong and post me the correct one
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Report post to moderator
Closing this thread as a duplicate of http://www.coderanch.com/t/608308/java/read-numbers-input-text-file
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!