+ 1
How i can save an array to a file and load it another time?
in c# and java
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 ]);
}
+ 3
check my code example