Skip to content

Debug error with text files

harish reddy

Asked Apr 10, 2018, 5:14 PM EDT1 answer
Share
LinkedInX
Hi.I am trying to write the below program. but error is coming . Also when i debug i am getting the error message like "could not copy....." as shown in the snapshot attached. This error comes frequently for any other programs also. why is it so?
 
Java
            //Write  simple program that counts how many times a substring(C#) occurs in a text file.

            //This is our "Intro to Programming in C#" book.In it you will learn the basics of C# programming.You will find out how nice C# is.



            StreamWriter writing = new StreamWriter(@"C:\Users\harish\Desktop\C Sharp\Practice\TextFiles\Occurences\Occurences.txt");
            int count = 0;

            if (File.Exists(@"C:\Users\harish\Desktop\C Sharp\Practice\TextFiles\Occurences\Occurences.txt"))
            {
                writing.Write("This is our Intro to Programming in C# book.In it you will learn the basics of C# programming.You will find out how nice C# is");

                writing.Close();

                StreamReader reading = new StreamReader(@"C:\Users\harish\Desktop\C Sharp\Practice\TextFiles\Occurences\Occurences.txt");
                Console.WriteLine(reading.ReadLine());


                string array = reading.ReadLine().Substring(0, 50);
                for (int i = 0; i < array.Length; i++)
                {
                    if (array[i] == 'C' && array[i + 1] == '#')
                    {
                        count++;
                    }
                } Console.WriteLine(count);




                reading.Close();
            }

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Rafnas T P
    0
    hi,
    it may be running code behind colse visual studio and open again and right click on the solution click on clean solution and again right click and click rebuild
    0