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
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.
You can use a Scanner and its nextInt() method.
In C, the fread() function is used to read data from a file and store it in a buffer.
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.
You can use a Scanner
and its nextInt()
method.
Scanner also has nextLong()
for larger integers, if needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With