Java File Input/Output - It's Way Easier Than You Think

แชร์
ฝัง
  • เผยแพร่เมื่อ 21 พ.ย. 2024

ความคิดเห็น • 337

  • @ungabunga7220
    @ungabunga7220 2 ปีที่แล้ว +262

    This is the first time i feel like i'm understanding everything in a coding tutorial. Your steps are so clear and you don't skip anything. You don't make anything complicated and show it as simple as it is. Perfect video. Thank you so much John, i hope you have a nice day!

    • @antunes6239
      @antunes6239 ปีที่แล้ว

      YHEAA
      i'm from Brazil,and by the first time,i understood how this work

    • @dushanchanuka1941
      @dushanchanuka1941 4 หลายเดือนก่อน

      Same here🎉😅

  • @ErikHansenDrums
    @ErikHansenDrums 3 ปีที่แล้ว +172

    really astounded that there aren't more clear cut tutorials/explanations about buffered reader/writer on YT. Thanks for the video!

  • @misaelpereira9679
    @misaelpereira9679 2 ปีที่แล้ว +63

    For anyone that does not know, you can use "try with resources" instead of closing the buffered items (and everything that implements closeable interface)

    • @flameyosflow_4834
      @flameyosflow_4834 ปีที่แล้ว +1

      In the latest java versions at least, you can only use try-with-resources when something implements AutoClosable

  • @Jmarthecat
    @Jmarthecat 2 ปีที่แล้ว +4

    You have no idea how happy I am when I search something related to Java and your video pops up.

  • @illegalgiant_
    @illegalgiant_ ปีที่แล้ว +12

    I've worked in this industry for years but as a lower level tech employee and am needing to brush up again. These tutorials are just fantastic. If you can understand why you'd do things this really clears up the rest. To boot, they are really concise and nicely made. Thanks man I do appreciate it.

  • @OmnispectiveHub
    @OmnispectiveHub 2 ปีที่แล้ว +32

    Perfect video. I can't begin to explain to you the confusion college classes give when explaining this type of stuff. Its great to have you as a resource for learning what they lack to teach properly. Much thanks, John.

  • @dasikalyan
    @dasikalyan 2 ปีที่แล้ว +8

    Yeah.. as someone pointed out.. try-with-resources is a good way to show best practice for any resource that implements closeable .. something like this
    try (BufferedWriter writer = new BufferedWriter(new FileWriter("output.txt"))) {
    writer.write("Writing to a file");
    } catch (Exception e) {
    e.printStackTrace();
    }

  • @shanisb95
    @shanisb95 2 ปีที่แล้ว +7

    Each time I am struggling with a notion on CodeGym I am on the lookout for one of your videos. And each time it gets crystal clear when you explain it. Thank you so much for your work !

  • @marksummers9543
    @marksummers9543 8 หลายเดือนก่อน

    you just help me finish a whole assignment in two hour over 3 videos, i appreciate you

  • @hkkabir2024
    @hkkabir2024 2 ปีที่แล้ว +3

    thank you for your excellency. now i don't need to check anywhere for reading and writing file. Millions of thanks

  • @HolyApplebutter
    @HolyApplebutter ปีที่แล้ว +2

    You're an absolute god-send. I've been struggling with these last couple weeks of the semester, but you're able to explain these concepts so easily with clear examples to help walk us through them. You're great!

  • @findlestick
    @findlestick 3 ปีที่แล้ว +10

    What? A concise, clearly-explained tutorial on TH-cam? Subbed. 👍

  • @TherealShacharTs
    @TherealShacharTs 9 หลายเดือนก่อน +1

    We were given an assignment to code all kinds of shapes, and the lecturer deliberately did not teach how to save files. And I asked him why they don't teach, but they did put it in the assignment, he said he wants us to learn to code and think twice about how everything works, only after watching your video, I understood the meaning of why he wanted it, there won't always be someone next to you to tell you, this is the stage you need study alone and look for answers

  • @lamiabakli3568
    @lamiabakli3568 5 หลายเดือนก่อน

    watching this right before my OOP exam, you're a life saver

  • @turboheadcrab666
    @turboheadcrab666 2 ปีที่แล้ว +2

    This is the easiest way to understand the I/O. The university teacher and other youtubers make this a tedious topic, but you made it so much easier. Thanks a lot!

  • @konstantinzakharov5643
    @konstantinzakharov5643 ปีที่แล้ว

    I watched this video, wrote some code and it works, Now I can reaaly write to and read from a file. Finally I wrote something that works. Thanks John!

  • @WannaBeProgrammer
    @WannaBeProgrammer 2 ปีที่แล้ว

    This is the first educational video I have slowed down the playback speed because I want to get every detail possible.

  • @limitless9483
    @limitless9483 ปีที่แล้ว

    As a JS engineer after starting to learn JAVA I've been wondering why every JAVA tutorial is recoreded in 320p quality with shitty audio !!!! finally a java tutorial with JS tutorials standards lol thank you so much.

  • @AdamZX1
    @AdamZX1 ปีที่แล้ว +1

    Hey John, regarding the 'while' loop, I'd rather simply implement it using '.ready()' i.e.:
    while (reader.ready())
    System.out.println(reader.readLine());
    Which does exactly the same thing as your code.
    Thank you for the great content and best regards !

    • @poorpanda9033
      @poorpanda9033 ปีที่แล้ว

      Woah! This is great. Thanks for sharing !!

  • @mbbthree
    @mbbthree ปีที่แล้ว

    Thank you! I kept getting a blank output, just needed to close the writer. God bless!

  • @redcrafterlppa303
    @redcrafterlppa303 2 ปีที่แล้ว +12

    That is an old and complicated way. The easiest way is to just put your lines in a list and call :
    Files.write("path","your list") ;
    That's all. You also need to handle the ioException though.
    Reading is simple too:
    List lines = Files.read("path").collect(Collectors.toList());

    • @francis.joseph
      @francis.joseph 2 ปีที่แล้ว

      will there be any performance issues if we use this

    • @redcrafterlppa303
      @redcrafterlppa303 2 ปีที่แล้ว +1

      @@francis.joseph I'm not sure but a raw loop with a filewriter is probably faster. But the point in this method is simplicity and reliability. Also 9/10 such performance differences are not important. If you write to a file many times a second you should think about refactoring the code and buffer the data.

  • @ouhyeap315
    @ouhyeap315 2 ปีที่แล้ว +1

    When I see your videos feels like Java is too easy but when I go to actually programming my brain just reseted

  • @rajacharya184
    @rajacharya184 2 ปีที่แล้ว

    thanks man you are like a savior in the hard times almost makes me wanna cry

  • @HelicopterRidesForCommunists
    @HelicopterRidesForCommunists 2 ปีที่แล้ว +1

    Man, I keep finding great video lessons like this that do a better job of explaining and teaching than my own PROFESSORS do. It is fucked up how expensive College is for what we get out of it aside from "certification", essentially, and a way to officially show we have taken the courses.

  • @justinliu7788
    @justinliu7788 2 ปีที่แล้ว +2

    You should close the resources in finally block or use a try with resources to guarantee the resources are closed. If you don't do this and there is some exception while running the writes, the resource will never be closed.

  • @dilln2158
    @dilln2158 3 ปีที่แล้ว +21

    Amazing, thank you for making this, very engaged with your viewers. This man is going places!

  • @Rosie-gj1pt
    @Rosie-gj1pt ปีที่แล้ว

    More clear than my teacher's explanation regarding Java IO! Thanks for the video so much❤

  • @oswaldovirto5896
    @oswaldovirto5896 ปีที่แล้ว +1

    You always come in clutch John. I was taught how to do this a year ago and I haven't had to use it since but this was a great refresher. Thank you!

  • @GourmetBytes
    @GourmetBytes ปีที่แล้ว +1

    lol, shameless plug of your course at beginning.... I hear less than 3 min of you speak and now I'm looking at that course like it's a nicely made steak dinner! Fantastic content! Both java knowledge and ability to teach!!!

  • @achellous8900
    @achellous8900 ปีที่แล้ว

    A very beautiful and calm way of redirecting knowledge! Respect

  • @AlexandreJasmin
    @AlexandreJasmin 2 ปีที่แล้ว +7

    This would be a good place to use Java’s try-with-resources statement which automatically close the file when leaving a code block.
    For a small program like this, main() can also be declared as “void main(String[] args) throws IOException” which would end the program and print a stack trace in case of error.

  • @dewy367
    @dewy367 8 หลายเดือนก่อน

    Thanks alot! So much easier than reading a lecture note when you have such an in depth summary

  • @dilln2158
    @dilln2158 3 ปีที่แล้ว +6

    This man is going places

  • @InvinciRD
    @InvinciRD ปีที่แล้ว

    Pls upload more vdos as i cant afford to spend more online .... You are my only hope towards fun learning...pls make every type vdo related coding ... i will watch and learn them all..

  • @marlon4415
    @marlon4415 10 หลายเดือนก่อน

    Your way of explaining is very good. You kinda like go through the way of thinking, your explanation is in a very logical order. I'm very impressed, very good 👍🏻

  • @nelsoncoop3774
    @nelsoncoop3774 ปีที่แล้ว +1

    if you create a PrintWriter instead of BufferedReader it comes with the normal print statements (print, println, printf) which is much easier and more familiar

  • @mastershonobi110
    @mastershonobi110 3 ปีที่แล้ว +20

    Ok, this videos was awesome. Currently taking Udemy’s “Java Programming Master Class” it’s very in-depth…and I’m always looking for Channels/videos like your to fill in the gaps and give a different/simpler explanation on what seems to be complex topics. You should offer private lessons in addition to your Course. IMHO. 🙌🏿🙌🏿🙌🏿

    • @CodingWithJohn
      @CodingWithJohn  3 ปีที่แล้ว +9

      If I can figure out a good way to do that when I have time, that's certainly an idea!

    • @mastershonobi110
      @mastershonobi110 3 ปีที่แล้ว +2

      @@CodingWithJohn I think it would be a very complimentary “course” for that course if nothing else. Just A Thought….
      P.S. I will be visiting your other vids to reinforce and fill in the gaps in other topics/areas in Java. e.g “LinkedList” ans pointers lmao..

    • @DragonOfTheWest412
      @DragonOfTheWest412 3 ปีที่แล้ว +1

      @@mastershonobi110 hey I’m taking that same class.

    • @mastershonobi110
      @mastershonobi110 3 ปีที่แล้ว

      @@DragonOfTheWest412 how far in are you???

    • @DragonOfTheWest412
      @DragonOfTheWest412 3 ปีที่แล้ว +1

      @@mastershonobi110 section 8 almost on 9 how about you ?

  • @skotosei9948
    @skotosei9948 ปีที่แล้ว

    YOU ARE THE GOAT BRO TY, AM FRENCH STUDENT AND YOU HELP ME SO MUCH, love you

  • @18kroger
    @18kroger 5 หลายเดือนก่อน

    You nailed it. A crystal clear explanation.

  • @mykevdc
    @mykevdc 2 ปีที่แล้ว +4

    You make it so easy to understand, thank you!

  • @jacobkurek5366
    @jacobkurek5366 2 ปีที่แล้ว

    Thanks for the great video. I'm a freshman in college studying CS and videos like this really help me get my projects done on time.

  • @kamui7424
    @kamui7424 ปีที่แล้ว

    Thanks for this bro, beginner here, and this really helped me a lot.

  • @RealCasualTrash
    @RealCasualTrash 3 ปีที่แล้ว +5

    Amazing work man! Helps a lot for revising(Learning everything from scratch) for uni exmas! Keep it up!

  • @nikhilsaimunagala2232
    @nikhilsaimunagala2232 2 ปีที่แล้ว +2

    This video really helped me learn File Input/Output properly. Btw, does it matter whether we choose File or Buffer Reader & Writer?

  • @abzzz-y7o
    @abzzz-y7o ปีที่แล้ว

    I have never seen a tutorial like this. Very cool

  • @Another0neTime
    @Another0neTime 2 ปีที่แล้ว +2

    Thanks, John. This was clear, concise, and educational.

  • @shantanupanditiitdelhi5515
    @shantanupanditiitdelhi5515 ปีที่แล้ว +1

    Very fantastic sir, the you was explaining that show how much you are cleared about concepts, thanks again master !!

  • @takeover6056
    @takeover6056 ปีที่แล้ว

    Thank you so much. You explain everything so easy and methodically.
    I am learning Java in Stockholm Sweden. Have a good evening!

  • @zeppelinmexicano
    @zeppelinmexicano 11 หลายเดือนก่อน

    It's good to have a "go to" set of objects/methods for this kind of work. I like the BufferedReader/Writer approach and if I'm not mistaken it will even scale up and allow an efficient job with larger data.

  • @mustafaturgut9930
    @mustafaturgut9930 ปีที่แล้ว

    I like the way you make every topic in java easy to understand. Please do more java videos

  • @vidyar1572
    @vidyar1572 ปีที่แล้ว

    Very Helpful Video. Please do a video on Serialization and De-serialization in JAVA with relevant examples. Thanks

  • @sararara7253
    @sararara7253 2 ปีที่แล้ว

    I heart you John! You make learning Java clear and understandable. Thank you for helping me learn more and drink less...(coffee). Cheers!

  • @priyanalpat
    @priyanalpat 2 ปีที่แล้ว

    I am a fan of your classes, simple and advanced. god job. Keep going

  • @madfilmer4349
    @madfilmer4349 ปีที่แล้ว

    Super method of teaching,able to understand hard concepts though..

  • @janfeyen592
    @janfeyen592 ปีที่แล้ว

    clear, concise and honestly reminds me that Java can be easier to manage than C

    • @CodingWithJohn
      @CodingWithJohn  ปีที่แล้ว

      It's been about 15 years since I've needed to code in C and I can't say I've missed it

    • @janfeyen592
      @janfeyen592 ปีที่แล้ว

      @@CodingWithJohn haha

  • @tanakamusungare6546
    @tanakamusungare6546 2 ปีที่แล้ว

    Thanks for making this concept much more understandable

  • @tazorun
    @tazorun 2 ปีที่แล้ว +1

    정말 좋은 수업 매일 매일 듣고 있습니다. 감사합니다. SUper easy to study.

  • @blind1936
    @blind1936 ปีที่แล้ว

    Always used scanner for this sort of things, and when I first time saw this monstrosity of a code at algorythmic test, I was terrified. Thanks to your tutorial now I uderstand it is preatty useful and easy to use. Thanks a lot and keep up the good work.

  • @johntravolta2655
    @johntravolta2655 2 ปีที่แล้ว

    I just can't stop watching you! Keep it going :)

  • @lyn8964
    @lyn8964 2 ปีที่แล้ว

    oh, finally understood this topic, thanks! You are the best Java teacher!

  • @BlueIsLeet
    @BlueIsLeet ปีที่แล้ว

    It's better to use try with resources because close() may not get called if the readLine() or write() throws an exception

  • @anjelomanoranjan
    @anjelomanoranjan ปีที่แล้ว

    I like ypu channel very much!!! You are my favorite englishspeaker youtube bloger, who makes Java Tutorials!!!

  • @maroofraktim293
    @maroofraktim293 3 หลายเดือนก่อน

    You're a gem. Keep going brother. Subbed.

  • @snoopie51
    @snoopie51 2 ปีที่แล้ว

    Thanks for being very understandable and simple, I’ve been kinda struggling with this.

  • @sintumavuya7495
    @sintumavuya7495 ปีที่แล้ว

    You were so clear and easy to understand. Thank you.

  • @sudheereddy6182
    @sudheereddy6182 2 ปีที่แล้ว

    You are one of the best who made this reader and writer concept look so simple and I really appreciate you work and effort. Thank you !

  • @tamalmazumder8476
    @tamalmazumder8476 27 วันที่ผ่านมา

    Thanks...Have a nice day!!

  • @boyneverstop
    @boyneverstop 2 ปีที่แล้ว +1

    This is very useful! Thank you for making this video!

  • @raandomplayer8589
    @raandomplayer8589 ปีที่แล้ว

    Watching this for advent of code. Thanks!

  • @a1rman906
    @a1rman906 3 หลายเดือนก่อน

    listen here u bastard.
    my professor has tried to teach it but couldnt make it that clear as u do it.
    u really are the goat.

  • @anushka.narsima
    @anushka.narsima 2 ปีที่แล้ว

    Your videos are so clear and concise, tysm!

  • @Garrison86
    @Garrison86 2 ปีที่แล้ว +1

    thank you, that was super easy to follow

  • @VikasNikhil
    @VikasNikhil 2 ปีที่แล้ว

    logical stuff in a few minutes. nice work

  • @zaph254
    @zaph254 10 หลายเดือนก่อน

    I just found my Java tutor, thank you God

  • @paulallen4622
    @paulallen4622 2 ปีที่แล้ว

    John your videos are amazing and helping me so much with my studies in software development!
    Keep doing what you are doing!

  • @asmewilliams7117
    @asmewilliams7117 4 หลายเดือนก่อน

    At 2:30, actually the set is written on the fly even without the close() method being called.
    Edit: My bad, I used a Try With Resources, that's why I didn't need to call close() which is called automatically with TWR.

  • @doniagasmi2192
    @doniagasmi2192 2 ปีที่แล้ว

    you make everything clear and simple. Thank you!

  • @darkojitsu
    @darkojitsu ปีที่แล้ว

    John, this is awesome! I really appreciate this tutorial.

  • @arush5596
    @arush5596 6 หลายเดือนก่อน

    felt like I understood a lot, but can you make a video about solving some mediocre level questions of file handling

  • @dinohunter7176
    @dinohunter7176 2 ปีที่แล้ว +1

    I love your videos, straight on point and easy to understand.

  • @mr.schrodinger7
    @mr.schrodinger7 6 หลายเดือนก่อน

    diificult concepts seem very ease when they are taught by u

  • @vpenywise
    @vpenywise 3 ปีที่แล้ว +1

    Liked, shared, subscribed, commented... Loving your content, thank you!

    • @parthsalat
      @parthsalat 2 ปีที่แล้ว +2

      Every youtuber needs to know your location lol

  • @bibeksharma600
    @bibeksharma600 2 ปีที่แล้ว +1

    Greatly explained....Need more contents ! :D

  • @hassanlearning4086
    @hassanlearning4086 ปีที่แล้ว

    Thank you for creating such informative and helpful content. Your explanation of Java File Input/Output made a difference in understanding this complex concept.
    P.S. wrote/read the above comments from this lesson FileIO in Eclipse! Thanks

  • @PROS3KUTOR
    @PROS3KUTOR 2 ปีที่แล้ว

    If someone doesn't wanna deal with a try-catch block everytime you wanna create or read a file, simple declare your main function like this:
    public static void main(String args[]) throws IOException
    {
    ... //Your code goes here
    }

  • @UPlusPlus
    @UPlusPlus 7 หลายเดือนก่อน +1

    Thank you ❤❤🥰🥰

  • @recipeFor
    @recipeFor 2 ปีที่แล้ว

    Your videos are always needed. Thanks

  • @canhle3970
    @canhle3970 2 ปีที่แล้ว

    Thanks a lot, John. You're really my saver there on my way to master Java !!!

  • @simplestep5449
    @simplestep5449 วันที่ผ่านมา

    but what if the text made of a lot of paragraphs and it needs an empty line whenever has a new paragraph, will the read code still works? anyway, great video, thanks sir John!

  • @Bunjo00
    @Bunjo00 9 หลายเดือนก่อน

    You awesome man, that was super easy to follow!

  • @ShermukhammadKarimov
    @ShermukhammadKarimov 7 หลายเดือนก่อน

    thanks for clear explanation.

  • @revan_hajiyev
    @revan_hajiyev 8 หลายเดือนก่อน

    thanks John, what a smooth explanation, i got it)

  • @bultibulti6716
    @bultibulti6716 9 หลายเดือนก่อน +2

    Can you please create a video to compare ip/Op .xls file with some transformation logic applied.

  • @kunpeng8646
    @kunpeng8646 2 ปีที่แล้ว

    John, god bless you! You are a amazing teacher!

  • @fatimazaid1593
    @fatimazaid1593 ปีที่แล้ว

    this is a perfect explanation , thank you sooo mucchhhhhhhh

  • @aye.myatmon4485
    @aye.myatmon4485 ปีที่แล้ว

    Thank you! John . For being my compiler .

  • @sadiconfrans3950
    @sadiconfrans3950 3 ปีที่แล้ว

    This video deserves more views!

  • @tinongsot6267
    @tinongsot6267 2 ปีที่แล้ว

    great job, u made it looks so simple!! love it

  • @FireDragon91245
    @FireDragon91245 2 ปีที่แล้ว

    im using a print writer most of the time

  • @juanalfredochavezhidalgo42
    @juanalfredochavezhidalgo42 2 ปีที่แล้ว

    the best video that I've ever seen