开发者

what is bad about this TextWriter method?

alt text http://img179.imageshack.us/img179/7827/textwriter.jpg

the tf.txt file has 0 bytes and when calling this method several times over the loop I get:

the process cannot access " " because it is being used by ano开发者_如何学Pythonther process


Yes, you're not closing the TextWriter. Thus the file handle remains open, so you can't create another one writing to the same file.

Use a using statement:

// Consider using File.CreateText instead, btw
using (TextWriter writer = new StreamWriter(...))
{
    ...
}

I'm surprised that your file is empty, admittedly... did it throw an exception the first time you called it, e.g. in GetTerms()? That would explain it. You might need a using statement for IndexReader as well, by the way - we can't really tell.


Why is tw.Close commented out? This might be the cause of "is being used by another process" since the file would be held open until closed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜