2011-08-15 1 views
1

を遮断します私は、指定されたcsvファイル上で動作する、以下のプログラムがあります。最後の数行は

using System; 
using System.Collections.Generic; 

class Program 
{ 
    static void Main(string[] args) 
    { 
     string path = @"C:/Documents and Settings/expn261/Desktop/SAPHR_Joiners_20110812.csv"; 
     string strCharater = File.ReadAllText(path,UTF7Encoding.UTF7); 

     strCharater = strCharater.ToString(); 

     strCharater = Regex.Replace(strCharater, "[èéèëêð]", "e"); 
     strCharater = Regex.Replace(strCharater, "[ÉÈËÊ]", "E"); 
     strCharater = Regex.Replace(strCharater, "[àâä]", "a"); 
     strCharater = Regex.Replace(strCharater, "[ÀÁÂÃÄÅ]", "A"); 
     strCharater = Regex.Replace(strCharater, "[àáâãäå]", "a"); 
     strCharater = Regex.Replace(strCharater, "[ÙÚÛÜ]", "U"); 
     strCharater = Regex.Replace(strCharater, "[ùúûüµ]", "u"); 
     strCharater = Regex.Replace(strCharater, "[òóôõöø]", "o"); 
     strCharater = Regex.Replace(strCharater, "[ÒÓÔÕÖØ]", "O"); 
     strCharater = Regex.Replace(strCharater, "[ìíîï]", "i"); 
     strCharater = Regex.Replace(strCharater, "[ÌÍÎÏ]", "I"); 
     strCharater = Regex.Replace(strCharater, "[š]", "s"); 
     strCharater = Regex.Replace(strCharater, "[Š]", "S"); 
     strCharater = Regex.Replace(strCharater, "[ñ]", "n"); 
     strCharater = Regex.Replace(strCharater, "[Ñ]", "N"); 
     strCharater = Regex.Replace(strCharater, "[ç]", "c"); 
     strCharater = Regex.Replace(strCharater, "[Ç]", "C"); 
     strCharater = Regex.Replace(strCharater, "[ÿ]", "y"); 
     strCharater = Regex.Replace(strCharater, "[Ÿ]", "Y"); 
     strCharater = Regex.Replace(strCharater, "[ž]", "z"); 
     strCharater = Regex.Replace(strCharater, "[Ž]", "Z"); 
     strCharater = Regex.Replace(strCharater, "[Ð]", "D"); 
     strCharater = Regex.Replace(strCharater, "[œ]", "oe"); 
     strCharater = Regex.Replace(strCharater, "[Œ]", "Oe"); 
     //strCharater = Regex.Replace(strCharater, "[«»\u201C\u201D\u201E\u201F\u2033\u2036]", "\""); 
     //strCharater = Regex.Replace(strCharater, "[\u2026]", "..."); 

     string path2 = (@"C:/Documents and Settings/expn261/Desktop/file.csv"); 
     StreamWriter sw = new StreamWriter(path2); 
     sw.WriteLine(strCharater,UTF7Encoding.UTF7); 
    } 
} 

を問題は、私は最後の3か4行にそれを実行ファイルにかかわらずであるということです表示されません。

何が問題なのですか?

+0

ストリームライターを閉じているわけではありません。 – FlyingStreudel

+0

私はHinekがやって来るまで答えを出すつもりはなかった。彼の答えは「治癒」ですが、問題を説明するものではありません。あなたはストリームライターを閉じていないので、バッファを書き出しません。ストリーム上でClose()を呼び出すことができますが、Using(){}のパターンが優れています。 – iandotkelly

答えて

2

あなたが好き、){}(使用にStreamWriterとしてIDisposablesを使用する必要があります。

この場合
using(StreamWriter sw = new StreamWriter(path2)) 
{ 
    sw.WriteLine(strCharater, UTF7Encoding.UTF7); 
} 

、きれいな処分は、それはそれは、バッファの書き込みをするようになりますStreamWriterClose()メソッドを呼び出します。ファイルに追加します。