Jump to content
  • 0

ostatní File.WriteAllLines(path, lines) // pomoc \\


ERIK518

Dotaz

Čaute potreboval by som pomôcť so zapisovaním dát do súboru ( .txt ) kód vyzerá následovne :

 

        private void CreateFile()
        {
            string pathString2 = @"c:\Firm\Zoznam.txt";
            string[] lines = { "empty" , "empty", "empty", "empty" , "empty", "empty", "empty", "empty", "empty", "empty", "empty", "empty", "empty", "empty", "empty", "empty", "empty", "empty",  };
            if (!Directory.Exists(pathString2))
            {
                File.Create(pathString2);
                File.WriteAllLines(pathString2, lines);  <--- TUNA je chyba "The process cannot access the file 'c:\Firm\Zoznam.txt' because it is being used by another process." ( .txt súbor je zatvorený neviem prečo to píše )
            }
        }

 

 

 

Vopred ďakujem za každú dobrú radu :)

Link to comment
Share on other sites

6 odpovědí na tuto otázku

Recommended Posts

  • 0

A přeložil sis ten error? :d

Proces nemá přístup k souboru "c: \ Firma \ Zoznam.txt", protože je používán jiným procesem

To znamená že již někde máš nastavený zapisování do toho to souboru nebo jeji jinej systém využívá :)

Link to comment
Share on other sites

  • 0

File.Create ti vrati instanciu otvoreneho suboru ktory vytvoril. Tak ze musis zapisovat do danej instancie alebo si pocakt kym to garbage collector zavre.

FileStream fs = File.Create("1235.txt");

fs.Write(lines, 0);

 

 

pokial viam, pripadne kukni google

Link to comment
Share on other sites

  • 0

Prišiel som na to že File.Create a File.WriteAllLines sú ako keby tie isté lebo som mal takto kód 

 

 

        private void CreateFile()
        {
            string pathString2 = @"c:\Firm\Zoznam.txt";
            if (!File.Exists(pathString2))
            {
                File.Create(pathString2);
            }
        }
 
        private void WriteData()
        {
            string pathString2 = @"c:\Firm\Zoznam.txt";
            string[] lines = { "empty", "empty", "empty", "empty" };
            if (!File.Exists(pathString2))
            {
                File.WriteAllLines(pathString2, lines);
            }
        }

 

 

a potom som dal preč public void CreateFile a nechal iba WriteData a už to ide :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...