C# Tutorial 17 File I/O

Поділитися
Вставка
  • Опубліковано 22 січ 2025

КОМЕНТАРІ • 154

  • @cabbage5257
    @cabbage5257 2 роки тому +3

    i like how you explain what each and every one of your code does. this really helps my learning experience as i waste 20:44 min of my life basically learning nothing

  • @ronaldabellano5643
    @ronaldabellano5643 5 років тому +3

    I like the variety of how you create an instance of a stream.

  • @Lunsterful
    @Lunsterful 8 років тому +41

    Small error at about 3:40 - new DirectoryInfo() does not create a new directory on the file system. Check the .Exists property. Needs to be done with Directory.CreateDirectory. Otherwise nice work.

    • @derekbanas
      @derekbanas  8 років тому +8

      Whoops sorry about that

    • @SpeedyBangBong
      @SpeedyBangBong 7 років тому +3

      Lunsterful, I was looking for that comment! Thanks.
      Derek, watched all the C# videos (and much more) big thanks for your amazing work!

    • @flowerpower1951
      @flowerpower1951 6 років тому +1

      @@derekbanas Just learning C# - instead of the suggested "Directory.CreateDirectory" I have used "dataDir.Create(); seems to work OK

    • @mariopellegrino7661
      @mariopellegrino7661 6 років тому

      I should've looked at the comments before panicking lol. It wasn't working for me, and I ended up looking all around the Internet for why it wasn't working and found your solution along the way. Thanks for pointing this out!

    • @RP-mp4ow
      @RP-mp4ow 6 років тому

      THANK YOU SO MUCH!

  • @HodgePigChannel
    @HodgePigChannel 7 років тому +1

    First video I've watched but will definitely watch the others.
    By far the most informative and well laid out tutorial I've seen.
    Straight to the point and clearly shows how methods can be used.

    • @derekbanas
      @derekbanas  7 років тому

      Thank you for the compliment :)

  • @ivanpersons1813
    @ivanpersons1813 4 роки тому

    I like that you get write (pun intended) to the point and not waste time, telling us useless information about anything and everything.

    • @derekbanas
      @derekbanas  4 роки тому

      I do my best to not waste peoples time :)

  • @michaelsheldrew1818
    @michaelsheldrew1818 4 роки тому

    Derek, i appreciate your straight to the point and condensed information. I have to watch them a few times but i would rather it be that way that slower. This seems to be your style and you seem to be the only one i can find on UA-cam that condenses this information in such a concise and direct manner. I enjoy your wide variety of examples and the many options that you show us so that we can then choose what we need. I would like this video a million more times but unfortunately it only lets me like it once.

    • @derekbanas
      @derekbanas  4 роки тому

      Thank you for the very nice message :) Yes I go out of my way to be different from the other channels on YT. I think I'm the only person that covers such a wide range of topics and who makes heavily edited long videos. I'm glad you like them.

  • @Antheius
    @Antheius 5 років тому +1

    Derek Banas - The savior of computer science students.
    Also, platinum :D

    • @derekbanas
      @derekbanas  5 років тому

      Thank you :) I'm happy to be of service

  • @eladmizrahi8461
    @eladmizrahi8461 8 років тому +22

    Great as always, Thanks for those tutorials!
    I've learned so much from your channel :)

    • @derekbanas
      @derekbanas  8 років тому +7

      Thank you :) I'm very happy to hear that!

  • @xceinie
    @xceinie 10 місяців тому

    I gave this video a like within the first 19 seconds. Why? Because you clearly laid out your video in a nice way, and your title is descriptive and helpful for understanding that what you're going to go over will likely help me. I appreciate it!

  • @CanadianMang
    @CanadianMang 6 років тому +29

    Derek I wish you would make these videos twice as long and really take more time in explaining everything slower. These videos seem so rushed. I really like the videos but I always need to rewind and pause. Also you seem to gloss overthings when really if you explained them in detail I think people would learn better from watching these videos.

    • @oz7075
      @oz7075 5 років тому +3

      Can't agree enough with you, Erik. Luckily for me, I knew some of these things and watching this video helped me refresh and definitely take in new stuff faster, though sometimes this formula is not the best. This said, I want to thank Derek for taking the time to do this series of videos that I will watch every and now and then.

  • @clashgamerxp8507
    @clashgamerxp8507 8 років тому +7

    best C# tutorial series out there :P thanks :)

    • @derekbanas
      @derekbanas  8 років тому +2

      Thank you :) I'm trying to cover everything

    • @clashgamerxp8507
      @clashgamerxp8507 8 років тому +3

      Derek Banas ik and you're doing a remarkable job at it :) so thank you :)

  • @xaviercomelli
    @xaviercomelli 6 років тому +30

    Ok tutorial -but it would be more useful if time were explained on why things work one way instead of just showing...

  • @salmali9039
    @salmali9039 Рік тому

    Do you can solve this;
    Build Application that has three classes (three user data types). Every class has
    some of attributes and methods to manipulate the objects of these classes.
    The objects and their data can be saved permanently into Files. Every class have
    to save in three forms of files:
    1. Object Stream.
    2. Data Stream.
    3. Random Access File Stream.
    Data can be brought mainly from csv file. Every record consists of multiple fields,
    and every line has only one record,

  • @ajacobs100
    @ajacobs100 7 років тому +8

    i always listen to derek banas in x2 speed ;P

  • @dadsire-TV
    @dadsire-TV 7 років тому

    I feel so much better after watching this.

    • @derekbanas
      @derekbanas  7 років тому

      Thank you very much :) I'm happy that you liked it

  • @saalam6880
    @saalam6880 6 років тому +2

    A question, when Reading data with filestreams, Why is it we need to create an additional bytearray to store the bytes from rsByteArray, Why not just get the rsByteArray and use the .GetString function on that?

  • @fathimashoukath4884
    @fathimashoukath4884 4 роки тому

    Why do we need to create a byte array to hold file data or fileByteArray ?can't we directly output the rsByteArray?

  • @mritunjaygiri3626
    @mritunjaygiri3626 4 роки тому

    sir i am facing one problems in my asp.net project.....i use many master pages and more than 20 content pages of one master page the problem is how to manage all folders...in solution explorer there is more than 300 folders how to merge one master page and its content page in one folder. pls help me i search every where but no any result

  • @exact-itacademy1282
    @exact-itacademy1282 6 років тому

    I really like the you speak your american english! like someone talking to his own heart

  • @jonlbs7
    @jonlbs7 4 роки тому

    I realize that this video is over 3 years .. I'm wondering what kind of application can read the testFile4.dat that is produced at the very end. I tried opening with Excel and LibreOffice Calc which rendered Random Text*@ and then garbleDgook.. I tried Unicode (UTF-8)..

    • @rodmanunderhilliii8198
      @rodmanunderhilliii8198 4 роки тому

      What I found is.... A file with the . dat file extension is a generic data file, that stores specific information relating to the program that created the file. So I tried opening it with VS, since that is what created it. No, luck opening it that way.
      It's not always a text file, and it can be in use, with an app., making it hard to delete. Remember the index.dat, back in the day, that kept a log of every site you visited; I couldn't delete it, but could delete the content.
      So, to open the dat file, I used HxD Hex Editor app to view/edit it.

  • @Felm84
    @Felm84 7 років тому +1

    First of all, thank you for the videos Derek. Would you mind to teach us serialize and deserialize data with C#? Thank you.

    • @derekbanas
      @derekbanas  7 років тому +2

      I'm happy to help and plan on covering that in the next video :)

  • @HaldunT
    @HaldunT 5 років тому

    You are great. Thanks for teach us.

    • @derekbanas
      @derekbanas  5 років тому +1

      Thank you for the compliment :) It is my pleasure to help

  • @stevefrt9495
    @stevefrt9495 7 років тому

    Thanks you so much Derek your video are the best

  • @frasermanley9903
    @frasermanley9903 5 років тому

    Is it possible to create and write to a text document as a different user? I'm building a digital forensic challenge creation toolkit using C# and powershell. I require the use of administration access to manipulate the flow of time within the toolkit however I would be interested if it were possible to write files as a standard user using the system.io library. I can achieve this using powershell however, the Lochard Principal really puts pressure on my design to limit any potential fingerprint where possible.

  • @aniruddhapoorna7649
    @aniruddhapoorna7649 5 років тому

    Hi how can we read a file from the middle of the file to the top of the file??

  • @caesar3346
    @caesar3346 6 років тому +2

    I can not speak and understand english. But dont know why I've understood this SYSTEM IO

  • @stavrostsirlidis3921
    @stavrostsirlidis3921 2 роки тому

    Awsome! Thx for really good explaination!

    • @derekbanas
      @derekbanas  2 роки тому

      Thank you :) I'm happy you enjoyed it

  • @orthodox-4-ever
    @orthodox-4-ever 7 років тому +1

    Dont give up Derek! :-)

    • @derekbanas
      @derekbanas  7 років тому +4

      I've been doing this for 7 years and I don't plan on quitting :)

  • @tim-timman8868
    @tim-timman8868 7 років тому

    You're videos are great both for leaning and refreshing. Keep up the good work. Would it be simple enough to cover how to read data from input devices using C# (particularly gamepads)? Also platinum!

    • @derekbanas
      @derekbanas  7 років тому

      Thank you very much :) Sure I'll cover how to handle input. I'll start making games soon

  • @cyborg6294
    @cyborg6294 7 років тому

    Do we can use these codes also with forms too or just for consoles ? Thank you so much for your fantastic work.

    • @derekbanas
      @derekbanas  7 років тому

      Yes I get into forms very soon

    • @cyborg6294
      @cyborg6294 7 років тому

      That would be amazing, it just where I'm studying right now as a first year in faculty, we are studying everything in WinForms, even i don't know, it is an old technology right now while already we have WPF, or it is still in use. While our professor said that WPF requires that you master a large number of quite difficult concepts before you even get around to writing a line, and you will get disheartened very quickly because of this reason. Also we choose WinForms if they have to expand the reach of their software to other operating systems. Mono/xamarin do not support WPF and it would take some time for them to. WinForms it meant to be cross platform code on C#. Also in my experience, a WPF application takes up more RAM than its Windows Forms counterpart. Also I think that with WPF we can create Windows Phone and Windows Store apps, while with WinForms we cannot, correct me if I'm wrong. You are doing a really amazing and a great job for students, enthusiasts, amateurs and for humanity after all. And sorry for my English but i will also work on it so soon to make it better.

  • @patyue5012
    @patyue5012 6 років тому

    Derek, are you based on your recommended book to make these C# tutorials? Thank you.

    • @derekbanas
      @derekbanas  6 років тому

      I have a professor friend poll students to see what books they prefer

  • @Rudransh-kb6qr
    @Rudransh-kb6qr 5 років тому

    File.WriteAllLines(textFilePath, customers);
    Error : Directory not found exception was unhandled

    • @derekbanas
      @derekbanas  5 років тому

      I have working code here www.newthinktank.com/2017/03/c-tutorial-17/

  • @eluneth3925
    @eluneth3925 8 років тому +1

    Hey derek!, do you have any tutorial for c# form application?. As always great video! :)

    • @derekbanas
      @derekbanas  8 років тому +1

      Thank you :) WPF and XAML is coming next week

  • @Layarion
    @Layarion 6 років тому

    Can you make a video about creating a C# RegEx Console app? I want to find and replace things in some html documents.

    • @derekbanas
      @derekbanas  6 років тому

      Sorry, but I'm not sure what you want to do

  • @Onomandah
    @Onomandah 6 років тому

    A question. What is the @ letter before the strings? I have been googling it for 10 minutes and can't find the answer...

    • @Nick-jb4xi
      @Nick-jb4xi 6 років тому

      It treats the string as it is written. so you don't need to put slashes to make certain characters work. Although " are still an issue, because they are still used to end the verbatim string, as it is called.

  • @tobiasvinblad5139
    @tobiasvinblad5139 6 років тому

    Thank you for your well-made video. I really learned something👌👍

    • @derekbanas
      @derekbanas  6 років тому

      I'm very happy I could help :)

  • @sovanraksa2112
    @sovanraksa2112 6 років тому

    Great as always!

  • @SunnyApples
    @SunnyApples 7 років тому

    Thank you kindly for another amazing video. :)

    • @derekbanas
      @derekbanas  7 років тому

      You're very welcome :) Thank you

  • @DxGrumpzz
    @DxGrumpzz 7 років тому

    Hello Derek, I've been trying to follow this tutorial but when I use "File.WriteAllLine(TextFilepath, Customers);"
    it throws a "Directory not found Exception" I've tried creating a folder with windows and making a legit directory with cmd
    But nothing worked can you please help me.

    • @derekbanas
      @derekbanas  7 років тому

      Hello, You have a little bug. Try File.WriteAllLines(textFilePath, customers); You forgot the s

    • @DxGrumpzz
      @DxGrumpzz 7 років тому

      I forgot to wirte the 's' in Lines in the comment but not in the code. I've managed to fix it I had to manually write "DataDir.Create()" after initiallizing "DirectoryInfo DataDir"

    • @derekbanas
      @derekbanas  7 років тому

      Great I'm glad you fixed it. Sorry I couldn't help quicker

  • @MRahman13
    @MRahman13 6 років тому

    How can you add more text to the file after sr.Close()?

    • @derekbanas
      @derekbanas  6 років тому

      You have to open it again

    • @Victor_Marius
      @Victor_Marius 5 років тому

      @@derekbanas By default it appends content to the file when writing? What about rewriting from the beginning of the file. Do you have to delete and recreate it, and then to write it?

  • @lastone1222
    @lastone1222 5 років тому

    Thanks for the tutorial this is what I was looking for. But how can I read write and create files which are saved in individual paths? Example - someone installs the program to the disc D but in code is given dir to desktop on the disc C. Does IO system offers path reading?
    I know there is smth like Environment.MachineName and so on, but in this case you have to define a lot of strings to get the whole path.

  • @definepollution4370
    @definepollution4370 7 років тому

    what is I what to make this on one computer then open it it on a different pc?

    • @derekbanas
      @derekbanas  7 років тому

      C# programs can be compiled as executables on any OS

    • @definepollution4370
      @definepollution4370 7 років тому +1

      what if the Directory is set for my pc. Not the other pc.

  • @umarnaeem6128
    @umarnaeem6128 7 років тому

    What if i have a text file having two Columns of integers separated by "\t" like this:
    12 23
    14 56
    56 67
    ... ....
    n i want that the integers of first column gets store in an array
    ( Like this: x[0]=12,x[1]=14, x=[2]=56 n so on ) , and the 2nd one gets store in 2nd array, How it can be Done ? and wt class should we use for this, StreamReader, FIlestream e.t.c. . . .

    • @Victor_Marius
      @Victor_Marius 5 років тому

      int i = 0;
      int x[], y[];
      foreach(string line in File. ReadAllLines(textFilePath)) {
      string[] s = line. Split("\t");
      x[i] = Convert. ToInt32(s[0], 10);
      y[i++] = Convert. ToInt32(s[1], 10);
      }

  • @KaranLobana
    @KaranLobana 8 років тому

    Hey Derek, I want your professional opinion about a project I have undertaken. Its a frontend heavy web app and I require a good framework for this. Im thinking about using one of these: Angular2, AngularDart, VueJS, Polymer, AureliaJS. I cant decide which one to use!

    • @derekbanas
      @derekbanas  8 років тому

      Tell me more and I'll give you my opinion based on your goal

    • @KaranLobana
      @KaranLobana 8 років тому

      Derek Banas Well the apps main page has a "wall" that resembles FBs wall, apart from that we have a user profile page, a page to view posts, basically the whole 9 yards of a social media app. Im not at liberty to disclose project details so I hope this will be enough.

    • @gabriellindemann2163
      @gabriellindemann2163 7 років тому

      I'm actually using Vue for a similar project.

    • @derekbanas
      @derekbanas  7 років тому

      I personally would use PHP / Laravel to design a site like that, but that is just what I'm used to using

  • @gregocchiogrossi906
    @gregocchiogrossi906 7 років тому

    Hi Derek, I have been having difficulty sending commands to cmd. I have tried using streamwriter and processes. Is there a different method I should be using? Thank you for your time.

  • @gabriellindemann2163
    @gabriellindemann2163 7 років тому

    Hey Derek! I just thought, if it would perhaps be a good idea to build a community forums, or something like that, around your channel :) Just a place where we can talk and help each other, I think it would be great, especially with your comments on fan-building.

    • @derekbanas
      @derekbanas  7 років тому

      That would be great, but I'm a bit tied up right now. It is kind of hard to manage multiple comment systems. I actually had to shut the one off on my website because people kept trying to hack my site with it. I'll look into it.

  • @neelimgoswami6336
    @neelimgoswami6336 6 років тому

    thanks for the tutorials

  • @AmitKumar-he3dl
    @AmitKumar-he3dl 8 років тому

    visual studio is late is there any lite weight ide for c#

    • @derekbanas
      @derekbanas  8 років тому

      Sorry I don't understand the question. What do you mean by late?

    • @AmitKumar-he3dl
      @AmitKumar-he3dl 8 років тому

      i mean it is resource hungry and i don't have a good setup. So it runs slower on my system

    • @scopestacker9787
      @scopestacker9787 8 років тому

      SharpDevelop is your IDE.

    • @derekbanas
      @derekbanas  8 років тому

      Thank you for helping :)

    • @scopestacker9787
      @scopestacker9787 7 років тому

      No problem, I'm glad I could help :-)

  • @neelimgoswami6336
    @neelimgoswami6336 6 років тому

    from which age did you start learn programming?

    • @derekbanas
      @derekbanas  6 років тому

      I started 30 years ago around the age of 10, but I didn't get serious until about 15

  • @EduardoCGarza-cp8nt
    @EduardoCGarza-cp8nt 8 років тому

    thank you so much for this video! I'm really starting to like C#.
    I was wondering how you learn these languages before you make the videos?

    • @derekbanas
      @derekbanas  8 років тому +4

      Yes C# is great! Normally if I do a video I already know the language. If I have to learn a new language I normally get the best 2 books on the topic and read them. Then I write lots of programs while referring to the API, blogs, etc. to learn what isn't in books.

  • @niklaskarlsson236
    @niklaskarlsson236 8 років тому

    cool!
    If i come from a more "java-world" can i use dll-files and SDK from a C# project some how? (if i have the docks for the C# files)
    :-)
    thanks for your great videos!

    • @derekbanas
      @derekbanas  8 років тому

      Thank you :) Are you trying to execute C# from Java?

    • @niklaskarlsson236
      @niklaskarlsson236 8 років тому

      Yes...
      I have a sdk with dll:s and I like to use those functions in java..

  • @SuprunAlexey
    @SuprunAlexey 8 років тому +6

    Derek give me please some advices how to grow up my channel with Russian audience? You are my idol.

    • @derekbanas
      @derekbanas  8 років тому +21

      I don't understand the videos (I don't speak Russian) and I'm not sure if you want to hear this, but you are actually doing fantastic. You grew your channel to almost 5,000 subscribers in a year. In the education space that is just about the best you can expect. Look at my channel for an example. I have almost 600,000 subscribers, but really I only have about 2,000 fans. There is a great difference between subscribers and fans. You actually have a higher percentage of fans then I do. To increase your fans show yourself and your personality more. I wish I would have learned this lesson earlier. To most people I'm just a random voice. In your next video series try showing your face while you write code and see if the percentage drop off from video 1 improves versus video 2. That is the best gage of whether you are improving your videos or not. Maybe try increasing your font size a little. Your voice is great and the code is great. It takes time to build an audience. Don't make the same mistake I made. Build fans instead of subscribers.

    • @SuprunAlexey
      @SuprunAlexey 8 років тому +3

      Derek Banas thank you for your answer!

    • @mrterrbl8184
      @mrterrbl8184 6 років тому +2

      I really appreciate this genuine answer to his question.

    • @timmylol6
      @timmylol6 4 роки тому

      @@derekbanas the goat for this reply

    • @arpitsrivstva
      @arpitsrivstva 3 роки тому

      @@derekbanas personally, I don't agree to your answer as a whole. I dont like people showing their faces and try to become stars or gain fans or something on a thing like UA-cam by uploading random videos. That's just stupidity for me. i dont personally click those videos in which I see that kind of stuff like show off or trying to do some useless talk which increases the duration of the video. On the other hand I agree with the quality and font size thing you said. Most of the people I know, including me, are on UA-cam whenever they are, just to learn something or get entertained and your channel is for learning so they only want something straightforward and to the point, which you are giving, and that's why you have such success on here.

  • @RP-mp4ow
    @RP-mp4ow 6 років тому

    Platinum.
    Thank you for this video

    • @derekbanas
      @derekbanas  6 років тому +1

      I'm happy you liked it :)

  • @Starname64
    @Starname64 8 років тому

    Thanks for the tutorial! Platinum

  • @jerinmathew995
    @jerinmathew995 7 років тому

    I have subscribed😊

  • @Rudransh-kb6qr
    @Rudransh-kb6qr 5 років тому

    I am getting a error

  • @jorgfloy8905
    @jorgfloy8905 7 років тому

    Can you do GML in one video plz

    • @derekbanas
      @derekbanas  7 років тому

      Gamemaker or Geography Markup Language?

  • @Console.WriteLine
    @Console.WriteLine Рік тому

    thanks

  • @thehumblestudent5032
    @thehumblestudent5032 6 років тому +1

    //Creating a directory
    DirectoryInfo newDirectory = new DirectoryInfo(@"C:\Users\etc\etc");
    newDirectory.Create(); //This method will create a directory
    newDirectory.Delete(); //This method will delete the directory

  • @treskidchris2364
    @treskidchris2364 6 років тому

    File download not webclient

  • @ethanpixelate
    @ethanpixelate 7 років тому

    do LUA!

  • @orasis
    @orasis 7 років тому

    C# Reminds me of PASCAL.

    • @derekbanas
      @derekbanas  7 років тому +2

      Really? I always considered it a better version of Java

  • @stickmanbug
    @stickmanbug 8 років тому

    Awesome. :)!

  • @ellena1903
    @ellena1903 7 років тому +1

    Platinum :)

  • @patwicker1358
    @patwicker1358 8 років тому

    Platinum

    • @derekbanas
      @derekbanas  8 років тому

      Thank you for doing that :)

  • @m.k_69
    @m.k_69 8 років тому

    I did it I am First!!!!!!!!!!!

    • @derekbanas
      @derekbanas  8 років тому

      Congratulations :) That was fast

    • @m.k_69
      @m.k_69 8 років тому

      I am simple man I see your videos I click :) , and as always thank you for these good videos

    • @derekbanas
      @derekbanas  8 років тому

      I greatly appreciate it that you watch them :)

    • @patwicker1358
      @patwicker1358 8 років тому

      Yeah, too bad he didn't see the Platinum :-)

  • @thinhnguyen4233
    @thinhnguyen4233 5 років тому

    viet nam

  • @sgtfireball6471
    @sgtfireball6471 Рік тому

    :)

  • @saalam6880
    @saalam6880 6 років тому

    Platinum

  • @roostermaind6413
    @roostermaind6413 5 років тому

    Platinum

  • @cajogos
    @cajogos 4 роки тому

    Platinum