Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read integer values from text file [duplicate]

Tags:

java

Possible Duplicate:
Java: Reading integers from a file into an array

I want to read integer values from a text file say contactids.txt. in the file i have values like

12345
3456778
234234234
34234324234

i Want to read them from a text file...please help

like image 402
Cindrella Avatar asked May 25 '12 10:05

Cindrella


People also ask

How do I read an integer from a text file?

First example program - reading numbers from a text file Once the Scanner is open on the file, we can use the usual command nextInt() to read the next available integer from the file. The program will attempt to read all of the numbers in the text file and print them to the output pane.

Which of the following should be used to read an int value from a text file?

You can use a Scanner and its nextInt() method.

How do you read a buffer file?

In C, the fread() function is used to read data from a file and store it in a buffer.

How do you remove duplicates from a text file in Java?

Read each line of the file Store it in a Sting say input. Try to add this String to the Set object. If the addition is successful, append that particular line to file writer. Finally, flush the contents of the FileWriter to the output file.


1 Answers

You can use a Scanner and its nextInt() method.
Scanner also has nextLong() for larger integers, if needed.

like image 162
amit Avatar answered Oct 01 '22 17:10

amit