में काम नहीं कर रहा है कोड का यह टुकड़ा पूरी तरह से वीएस 2010 में काम करता है। अब मेरे पास वीएस 2013 है, यह अब फ़ाइल को नहीं लिखता है। यह त्रुटि या कुछ भी नहीं है। (मुझे नोटपैड ++ में एक चेतावनी मिलती है कि फ़ाइल अपडेट कर दी गई है, लेकिन कुछ भी लिखा नहीं गया है।)स्ट्रीमवाइटर सी #
यह सब ठीक दिखता है। कोई विचार?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
String line;
try
{
//Pass the file path and file name to the StreamReader constructor
StreamReader sr = new StreamReader("C:\\Temp1\\test1.txt");
StreamWriter sw = new StreamWriter("C:\\Temp2\\test2.txt");
//Read the first line of text
line = sr.ReadLine();
//Continue to read until you reach end of file
while (line != null)
{
//write the line to console window
Console.WriteLine(line);
int myVal = 3;
for (int i = 0; i < myVal; i++)
{
Console.WriteLine(line);
sw.WriteLine(line);
}
//Write to the other file
sw.WriteLine(line);
//Read the next line
line = sr.ReadLine();
}
//close the file
sr.Close();
Console.ReadLine();
}
catch (Exception e)
{
Console.WriteLine("Exception: " + e.Message);
}
finally
{
Console.WriteLine("Executing finally block.");
}
}
}
}
क्या आप सही निर्देशिका में देख रहे हैं? क्या आपने फाइल को सैनिटी चेक के रूप में खोला है? – user1666620
स्पष्ट रूप से फ्लश करने का प्रयास करें। – Lloyd
मैं कहीं भी नहीं देखता हूं जिसे आप sw कहते हैं। बंद करें(); यदि आप ऐसा करते हैं, तो लेखन फ़्लश हो जाएगा और फ़ाइल बंद हो जाएगी। साथ ही, आपको वास्तव में ब्लॉक का उपयोग करने में StreamReader और StreamWriter को लपेटना चाहिए - वे दोनों IDISposable लागू करते हैं, और जब आप ब्लॉक – thorkia