C# Tutorial 17 File I/O

Поделиться
HTML-код
  • Опубликовано: 12 сен 2024

Комментарии • 155

  • @cabbage5257
    @cabbage5257 Год назад +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

  • @Lunsterful
    @Lunsterful 7 лет назад +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  7 лет назад +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 5 лет назад +1

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

    • @mariopellegrino7661
      @mariopellegrino7661 5 лет назад

      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 5 лет назад

      THANK YOU SO MUCH!

  • @xceinie
    @xceinie 6 месяцев назад

    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!

  • @eladmizrahi8461
    @eladmizrahi8461 7 лет назад +22

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

    • @derekbanas
      @derekbanas  7 лет назад +7

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

  • @ronaldabellano5643
    @ronaldabellano5643 5 лет назад +3

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

  • @HodgePigChannel
    @HodgePigChannel 6 лет назад +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  6 лет назад

      Thank you for the compliment :)

  • @michaelsheldrew1818
    @michaelsheldrew1818 3 года назад

    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 RUclips 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  3 года назад

      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.

  • @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 :)

  • @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,

  • @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

  • @clashgamerxp8507
    @clashgamerxp8507 7 лет назад +7

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

    • @derekbanas
      @derekbanas  7 лет назад +2

      Thank you :) I'm trying to cover everything

    • @clashgamerxp8507
      @clashgamerxp8507 7 лет назад +3

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

  • @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.

  • @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?

  • @HaldunT
    @HaldunT 4 года назад

    You are great. Thanks for teach us.

    • @derekbanas
      @derekbanas  4 года назад +1

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

  • @dadsire-TV
    @dadsire-TV 6 лет назад

    I feel so much better after watching this.

    • @derekbanas
      @derekbanas  6 лет назад

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

  • @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...

  • @ajacobs100
    @ajacobs100 7 лет назад +8

    i always listen to derek banas in x2 speed ;P

  • @stavrostsirlidis3921
    @stavrostsirlidis3921 Год назад

    Awsome! Thx for really good explaination!

    • @derekbanas
      @derekbanas  Год назад

      Thank you :) I'm happy you enjoyed 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 :)

  • @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 :)

  • @stevefrt9495
    @stevefrt9495 6 лет назад

    Thanks you so much Derek your video are the best

  • @eluneth3925
    @eluneth3925 7 лет назад +1

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

    • @derekbanas
      @derekbanas  7 лет назад +1

      Thank you :) WPF and XAML is coming next week

  • @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

  • @tobiasvinblad5139
    @tobiasvinblad5139 5 лет назад

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

    • @derekbanas
      @derekbanas  5 лет назад

      I'm very happy I could help :)

  • @patyue5012
    @patyue5012 5 лет назад

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

    • @derekbanas
      @derekbanas  5 лет назад

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

  • @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?

  • @sovanraksa2112
    @sovanraksa2112 6 лет назад

    Great as always!

  • @exact-itacademy1282
    @exact-itacademy1282 5 лет назад

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

  • @SunnyApples
    @SunnyApples 7 лет назад

    Thank you kindly for another amazing video. :)

    • @derekbanas
      @derekbanas  7 лет назад

      You're very welcome :) Thank you

  • @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.

  • @caesar3346
    @caesar3346 5 лет назад +2

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

  • @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.

  • @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.

  • @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.

  • @neelimgoswami6336
    @neelimgoswami6336 6 лет назад

    thanks for the tutorials

  • @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.

  • @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

  • @Console.WriteLine
    @Console.WriteLine Год назад

    thanks

  • @aniruddhapoorna7649
    @aniruddhapoorna7649 5 лет назад

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

  • @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 5 лет назад

      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.

  • @RP-mp4ow
    @RP-mp4ow 5 лет назад

    Platinum.
    Thank you for this video

    • @derekbanas
      @derekbanas  5 лет назад +1

      I'm happy you liked it :)

  • @DambergStudios
    @DambergStudios 6 лет назад

    Hello! I need some help. So I am new to C# and currently working on a small project of mine. How do I make a program so when you run it, it will ask you about for example "how many subfolders do you want to create" and you type in the amount of folders that you wish to create and the program will do it. I have been stuck on this problem for quite some time now and can't find any solutions. Does anyone in here know? Basically only folders, no text files or anything like that. Thanks.

  • @jonlbs7
    @jonlbs7 3 года назад

    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 3 года назад

      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.

  • @Starname64
    @Starname64 7 лет назад

    Thanks for the tutorial! Platinum

  • @SuprunAlexey
    @SuprunAlexey 7 лет назад +6

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

    • @derekbanas
      @derekbanas  7 лет назад +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 7 лет назад +3

      Derek Banas thank you for your answer!

    • @mrterrbl8184
      @mrterrbl8184 6 лет назад +2

      I really appreciate this genuine answer to his question.

    • @timmylol6
      @timmylol6 3 года назад

      @@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 RUclips 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 RUclips 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.

  • @KaranLobana
    @KaranLobana 7 лет назад

    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  7 лет назад

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

    • @KaranLobana
      @KaranLobana 7 лет назад

      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

  • @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

  • @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

  • @niklaskarlsson236
    @niklaskarlsson236 7 лет назад

    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  7 лет назад

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

    • @niklaskarlsson236
      @niklaskarlsson236 7 лет назад

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

  • @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/

  • @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

  • @EduardoCGarza-cp8nt
    @EduardoCGarza-cp8nt 7 лет назад

    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  7 лет назад +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.

  • @jerinmathew995
    @jerinmathew995 6 лет назад

    I have subscribed😊

  • @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);
      }

  • @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

  • @Rudransh-kb6qr
    @Rudransh-kb6qr 5 лет назад

    I am getting a error

  • @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?

  • @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.

  • @cajogos
    @cajogos 3 года назад

    Platinum

  • @treskidchris2364
    @treskidchris2364 5 лет назад

    File download not webclient

  • @AmitKumar-he3dl
    @AmitKumar-he3dl 7 лет назад

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

    • @derekbanas
      @derekbanas  7 лет назад

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

    • @AmitKumar-he3dl
      @AmitKumar-he3dl 7 лет назад

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

    • @scopestacker9787
      @scopestacker9787 7 лет назад

      SharpDevelop is your IDE.

    • @derekbanas
      @derekbanas  7 лет назад

      Thank you for helping :)

    • @scopestacker9787
      @scopestacker9787 7 лет назад

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

  • @stickmanbug
    @stickmanbug 7 лет назад

    Awesome. :)!

  • @jorgfloy8905
    @jorgfloy8905 7 лет назад

    Can you do GML in one video plz

    • @derekbanas
      @derekbanas  7 лет назад

      Gamemaker or Geography Markup Language?

  • @orasis
    @orasis 7 лет назад

    C# Reminds me of PASCAL.

    • @derekbanas
      @derekbanas  7 лет назад +2

      Really? I always considered it a better version of Java

  • @ellena1903
    @ellena1903 7 лет назад +1

    Platinum :)

  • @ethanpixelate
    @ethanpixelate 7 лет назад

    do LUA!

    • @derekbanas
      @derekbanas  7 лет назад

      Here you go ruclips.net/video/iMacxZQMPXs/видео.html

    • @ethanpixelate
      @ethanpixelate 7 лет назад

      yay!

  • @thinhnguyen4233
    @thinhnguyen4233 5 лет назад

    viet nam

  • @sgtfireball6471
    @sgtfireball6471 Год назад

    :)

  • @m.k_69
    @m.k_69 7 лет назад

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

    • @derekbanas
      @derekbanas  7 лет назад

      Congratulations :) That was fast

    • @m.k_69
      @m.k_69 7 лет назад

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

    • @derekbanas
      @derekbanas  7 лет назад

      I greatly appreciate it that you watch them :)

    • @patwicker1358
      @patwicker1358 7 лет назад

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

  • @roostermaind6413
    @roostermaind6413 5 лет назад

    Platinum

  • @saalam6880
    @saalam6880 6 лет назад

    Platinum

  • @patwicker1358
    @patwicker1358 7 лет назад

    Platinum

    • @derekbanas
      @derekbanas  7 лет назад

      Thank you for doing that :)