EDN Admin
Well-known member
I have this code wich is working when writing a binary file:
<pre class="lang-cs prettyprint prettyprinted
[/code]
And this code to read back from the DAT file on the hard disk:
<pre class="prettyprint fileName = Options_DB.get_histogramFileDirectory();
if (File.Exists(fileName))
{
BinaryReader binReader =
new BinaryReader(File.Open(fileName, FileMode.Open));
try
{
//byte[] testArray = new byte[3];
int pos = 0;
int length = (int)binReader.BaseStream.Length;
binReader.BaseStream.Seek(0, SeekOrigin.Begin);
while (pos < length)
{
long[] l = new long[256];
for (int i = 0; i < 256; i++)
{
if (pos < length)
l = binReader.ReadInt64();
else
break;
pos += sizeof(Int64);
}
list_of_histograms.Add(l);
}
}
catch
{
}
finally
{
binReader.Close();
}[/code]
<br/>
But what i want to do is to add to the Writing code to write to the file more three streams like this:
<pre class="lang-cs prettyprint prettyprinted
[/code]
But the first thing is how can i write all this and make it in the file it self to be identify by a string or something so when im reading the file back i will be able to put each List to a new one ?
Second thing is how do i read back the file now so each List will be added to a new List ? Now its easy im writing one List reading and adding it to a List. But now i added more three Lists so how can i do it ?
Thanks. <hr class="sig danieli
View the full article
<pre class="lang-cs prettyprint prettyprinted
Code:
<span class="pln using <span class="pun (<span class="typ BinaryWriter<span class="pln binWriter <span class="pun =<span class="pln
<span class="kwd new<span class="pln <span class="typ BinaryWriter<span class="pun (<span class="typ File<span class="pun .<span class="typ Open<span class="pun (<span class="pln f<span class="pun .<span class="pln fileName<span class="pun ,<span class="pln <span class="typ FileMode<span class="pun .<span class="typ Create<span class="pun )))<span class="pln
<span class="pun {<span class="pln
<span class="kwd for<span class="pln <span class="pun (<span class="typ int<span class="pln i <span class="pun =<span class="pln <span class="lit 0<span class="pun ;<span class="pln i <span class="pun <<span class="pln f<span class="pun .<span class="pln histogramValueList<span class="pun .<span class="typ Count<span class="pun ;<span class="pln i<span class="pun ++)<span class="pln
<span class="pun {<span class="pln
binWriter<span class="pun .<span class="typ Write<span class="pun (<span class="pln f<span class="pun .<span class="pln histogramValueList<span class="pun [(<span class="typ int<span class="pun )<span class="pln i<span class="pun ]);<span class="pln
<span class="pun }<span class="pln
binWriter<span class="pun .<span class="typ Close<span class="pun ();<span class="pln
<span class="pun }
And this code to read back from the DAT file on the hard disk:
<pre class="prettyprint fileName = Options_DB.get_histogramFileDirectory();
if (File.Exists(fileName))
{
BinaryReader binReader =
new BinaryReader(File.Open(fileName, FileMode.Open));
try
{
//byte[] testArray = new byte[3];
int pos = 0;
int length = (int)binReader.BaseStream.Length;
binReader.BaseStream.Seek(0, SeekOrigin.Begin);
while (pos < length)
{
long[] l = new long[256];
for (int i = 0; i < 256; i++)
{
if (pos < length)
l = binReader.ReadInt64();
else
break;
pos += sizeof(Int64);
}
list_of_histograms.Add(l);
}
}
catch
{
}
finally
{
binReader.Close();
}[/code]
<br/>
But what i want to do is to add to the Writing code to write to the file more three streams like this:
<pre class="lang-cs prettyprint prettyprinted
Code:
<span class="pln binWriter<span class="pun .<span class="typ Write<span class="pun (<span class="pln f<span class="pun .<span class="pln histogramValueList<span class="pun [(<span class="typ int<span class="pun )<span class="pln i<span class="pun ]);<span class="pln
binWriter<span class="pun .<span class="typ Write<span class="pun (<span class="pln f<span class="pun .<span class="pln histogramValueListR<span class="pun [(<span class="typ int<span class="pun )<span class="pln i<span class="pun ]);<span class="pln
binWriter<span class="pun .<span class="typ Write<span class="pun (<span class="pln f<span class="pun .<span class="pln histogramValueListG<span class="pun [(<span class="typ int<span class="pun )<span class="pln i<span class="pun ]);<span class="pln
binWriter<span class="pun .<span class="typ Write<span class="pun (<span class="pln f<span class="pun .<span class="pln histogramValueListB<span class="pun [(<span class="typ int<span class="pun )<span class="pln i<span class="pun ]);
But the first thing is how can i write all this and make it in the file it self to be identify by a string or something so when im reading the file back i will be able to put each List to a new one ?
Second thing is how do i read back the file now so each List will be added to a new List ? Now its easy im writing one List reading and adding it to a List. But now i added more three Lists so how can i do it ?
Thanks. <hr class="sig danieli
View the full article