+ 1

How i can save an array to a file and load it another time?

in c# and java

17th Dec 2016, 4:13 PM
Amin Taghikhani
Amin Taghikhani - avatar
2 Answers
+ 4
c#: there is a static class named File in System.IO namespace it has a method CreatText(string path) this method returns a StreamWriter object which has write methods overloaded to accept all primitive types. here is an example: int [] intArray = new int[10]; string FilePath = "Temp.txt"; using (var SW = File.CreateText( FilePath )) foreach( int i in intArray) SW.Write(i +" "); // to read from file: int[] intValues; using (var SR= File.OpenText( FilePath )) { string[] StringValues = SR.ReadToEnd().Split(); intValues = new int[ StringValues.Length ]; for ( int I =0; i<StringValues-1 ; i++ ) intValues[ i ] = int.Parse( StringValues[ i ]); }
17th Dec 2016, 5:14 PM
HAL8999++;
HAL8999++; - avatar
+ 3
check my code example
17th Dec 2016, 6:02 PM
HAL8999++;
HAL8999++; - avatar