How should I assign some values from a txt file to an array in Java? -
I just say as the title started learning Java ... I would like to know that I am in Java some values How to work with an array in Java with an array (for example, to sort them).
For example C ++:
#includes & lt; Fstream & gt; using namespace std; Int v [10]; Int main () {ifstream fin ("num.txt"); Int i; (I = 0; i & lt; 10; i ++) fund & gt; & Gt; V [i]; } Thank you for the right people for all the information. I think that is a bit more complex than C ++, but I'll learn this. Also, when I was interning in a small company, I saw that the staff created a code that scans an XML file. I think it's too complicated, but it's fine.
If each line of the file is an integer:
list & lt; Integer & gt; Results = new arreelists & lt; Integer & gt; (); Try {File myFile = new file ("./ num.txt"); Scanner scanner = new scanner (mimefile); While (scanner.hasNextInt ()) {results.add (scanner.nextInt ()); }} Hold (FileNotFoundException e) {// error handling}
Comments
Post a Comment