C
CSharper
I have following code, if you cut and paste it in VS and compile it
you see only an answer of 0. I was expecting values from o through
2999
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Resources;
using System.IO;
using System.Collections;
namespace ResourceTester
{
class Program
{
static void Main(string[] args)
{
//File.Delete("my.resources");
//FileStream fs = new FileStream("my.resources",
FileMode.CreateNew, FileAccess.Write, FileShare.Write, 1,
FileOptions.None);
//ResourceWriter rw = new ResourceWriter(fs);
//for (int i = 1; i < int.MaxValue; i++)
//{
// Console.WriteLine(i.ToString());
// rw.AddResource(i.ToString(),
"XXXXXXXXXXXXXXXXXXXXXXXXXXX" + i.ToString());
//}
//rw.Generate();
//rw.Close();
//fs.Dispose();
//fs.Close();
FileStream fs = new FileStream("my.resources",
FileMode.Create, FileAccess.Write);
IResourceWriter rw = new ResourceWriter(fs);
for(int i=0;i<3000;i++)
{
rw.AddResource(i.ToString(),
"VVVVVVVVVVVVVVVVVVVVVVVVVVV " + i.ToString());
if (i % 1000 == 0)
{
//generate and free resource writer<br>
rw.Generate();
rw.Close();
//free stream<br>
fs.Dispose();
fs.Close();
//reload file<br>
fs = new FileStream("my.resources",
FileMode.Append, FileAccess.Write);
rw = new ResourceWriter(fs);
}
}
//generate and free resource writer<br>
rw.Generate();
rw.Close();
//free stream<br>
fs.Dispose();
fs.Close();
FileStream fsa = new FileStream("my.resources",
FileMode.Open, FileAccess.Read);
IResourceReader rd = new ResourceReader(fsa);
IDictionaryEnumerator dict = rd.GetEnumerator();
while (dict.MoveNext())
{
Console.WriteLine(dict.Key);
}
}
}
}
Any help would be appreciated.
What I am trying to achive is to create a resource file of 3000
numbers, well I could very well directly write the data to the
resource, in reality I want to write all the way up to int.MaxValue.
But when I write, I run into 'Out of Memory' exception. So based on
the suggestion I was told to close and append the file stream, when I
do that at the end I can see the file size is increasing but when you
read the data, only the first file flush data is available.
Thanks.
you see only an answer of 0. I was expecting values from o through
2999
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Resources;
using System.IO;
using System.Collections;
namespace ResourceTester
{
class Program
{
static void Main(string[] args)
{
//File.Delete("my.resources");
//FileStream fs = new FileStream("my.resources",
FileMode.CreateNew, FileAccess.Write, FileShare.Write, 1,
FileOptions.None);
//ResourceWriter rw = new ResourceWriter(fs);
//for (int i = 1; i < int.MaxValue; i++)
//{
// Console.WriteLine(i.ToString());
// rw.AddResource(i.ToString(),
"XXXXXXXXXXXXXXXXXXXXXXXXXXX" + i.ToString());
//}
//rw.Generate();
//rw.Close();
//fs.Dispose();
//fs.Close();
FileStream fs = new FileStream("my.resources",
FileMode.Create, FileAccess.Write);
IResourceWriter rw = new ResourceWriter(fs);
for(int i=0;i<3000;i++)
{
rw.AddResource(i.ToString(),
"VVVVVVVVVVVVVVVVVVVVVVVVVVV " + i.ToString());
if (i % 1000 == 0)
{
//generate and free resource writer<br>
rw.Generate();
rw.Close();
//free stream<br>
fs.Dispose();
fs.Close();
//reload file<br>
fs = new FileStream("my.resources",
FileMode.Append, FileAccess.Write);
rw = new ResourceWriter(fs);
}
}
//generate and free resource writer<br>
rw.Generate();
rw.Close();
//free stream<br>
fs.Dispose();
fs.Close();
FileStream fsa = new FileStream("my.resources",
FileMode.Open, FileAccess.Read);
IResourceReader rd = new ResourceReader(fsa);
IDictionaryEnumerator dict = rd.GetEnumerator();
while (dict.MoveNext())
{
Console.WriteLine(dict.Key);
}
}
}
}
Any help would be appreciated.
What I am trying to achive is to create a resource file of 3000
numbers, well I could very well directly write the data to the
resource, in reality I want to write all the way up to int.MaxValue.
But when I write, I run into 'Out of Memory' exception. So based on
the suggestion I was told to close and append the file stream, when I
do that at the end I can see the file size is increasing but when you
read the data, only the first file flush data is available.
Thanks.