This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
    Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

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

 
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
 
Bartender
Posts: 3320
86
  • 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
 
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
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!