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!
For anyone that does not know, you can use "try with resources" instead of closing the buffered items (and everything that implements closeable interface)
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.
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.
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 !
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(); }
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!
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.
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!
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
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.
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.
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 !
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 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..
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.
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.
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!!!
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
quick question from someone who wants to learn with best practice in 7:55 you make a comparison and declaration in the same line, wouldnt it be 'better' to use a do while loop where you declare in the do scope and compare in the while condition? like: String line; do { line = reader.readLine(); } while (line != null) EDIT: i just saw that if line is null in my example it would still print it, so is the solution in the video best practice? i face those situations a lot where you have something you would like to declare in the loop but also need it as a condition to end the loop and giving it an initial value is kinda boilerplate code since you have the loop for this, would like to get someone else's opinion on that. Thanks
7:58 Does the reader automatically go to the next line while executing the while loop (cause otherwise the first line would be printed over and over again)? I'm asking because we didn't specifically tell it to do so
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 👍🏻
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..
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.
Hey John, at 7:36 you showed a while loop. My question is that if there are 2 paragraphs, then wouldn't the reader just stop at the last line of the first paragraph and not further move on to the first line of the second paragraph?
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 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.
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.
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
Use this code. Pass output file name as well as "true" parameters for the file writer object. The true signifies boolean "append" = true. BufferedWriter writer = new BufferedWriter(new FileWriter ("Output.txt", true));
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!
YHEAA
i'm from Brazil,and by the first time,i understood how this work
Same here🎉😅
really astounded that there aren't more clear cut tutorials/explanations about buffered reader/writer on YT. Thanks for the video!
For anyone that does not know, you can use "try with resources" instead of closing the buffered items (and everything that implements closeable interface)
In the latest java versions at least, you can only use try-with-resources when something implements AutoClosable
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.
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.
You have no idea how happy I am when I search something related to Java and your video pops up.
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 !
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();
}
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!
What? A concise, clearly-explained tutorial on TH-cam? Subbed. 👍
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.
you just help me finish a whole assignment in two hour over 3 videos, i appreciate you
thank you for your excellency. now i don't need to check anywhere for reading and writing file. Millions of thanks
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!
Amazing, thank you for making this, very engaged with your viewers. This man is going places!
watching this right before my OOP exam, you're a life saver
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!
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!
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
Java One Liner Code, Very Basic to know for Java programmers,
th-cam.com/play/PLUPFEhEXH0fxH8DFJJOL6RW7Og4LewPL8.html
This is the first educational video I have slowed down the playback speed because I want to get every detail possible.
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.
Amazing work man! Helps a lot for revising(Learning everything from scratch) for uni exmas! Keep it up!
This man is going places
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.
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 !
Woah! This is great. Thanks for sharing !!
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. 🙌🏿🙌🏿🙌🏿
If I can figure out a good way to do that when I have time, that's certainly an idea!
@@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..
@@mastershonobi110 hey I’m taking that same class.
@@DragonOfTheWest412 how far in are you???
@@mastershonobi110 section 8 almost on 9 how about you ?
thanks man you are like a savior in the hard times almost makes me wanna cry
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.
Thanks alot! So much easier than reading a lecture note when you have such an in depth summary
You make it so easy to understand, thank you!
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.
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.
Thanks, John. This was clear, concise, and educational.
More clear than my teacher's explanation regarding Java IO! Thanks for the video so much❤
A very beautiful and calm way of redirecting knowledge! Respect
This video really helped me learn File Input/Output properly. Btw, does it matter whether we choose File or Buffer Reader & Writer?
When I see your videos feels like Java is too easy but when I go to actually programming my brain just reseted
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!!!
YOU ARE THE GOAT BRO TY, AM FRENCH STUDENT AND YOU HELP ME SO MUCH, love you
I heart you John! You make learning Java clear and understandable. Thank you for helping me learn more and drink less...(coffee). Cheers!
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
quick question from someone who wants to learn with best practice in 7:55 you make a comparison and declaration in the same line, wouldnt it be 'better' to use a do while loop where you declare in the do scope and compare in the while condition? like: String line; do { line = reader.readLine(); } while (line != null)
EDIT: i just saw that if line is null in my example it would still print it, so is the solution in the video best practice? i face those situations a lot where you have something you would like to declare in the loop but also need it as a condition to end the loop and giving it an initial value is kinda boilerplate code since you have the loop for this, would like to get someone else's opinion on that. Thanks
7:58 Does the reader automatically go to the next line while executing the while loop (cause otherwise the first line would be printed over and over again)? I'm asking because we didn't specifically tell it to do so
Thank you so much. You explain everything so easy and methodically.
I am learning Java in Stockholm Sweden. Have a good evening!
Thanks for this bro, beginner here, and this really helped me a lot.
Thank you! I kept getting a blank output, just needed to close the writer. God bless!
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 !
Thanks for being very understandable and simple, I’ve been kinda struggling with this.
oh, finally understood this topic, thanks! You are the best Java teacher!
I am a fan of your classes, simple and advanced. god job. Keep going
Very fantastic sir, the you was explaining that show how much you are cleared about concepts, thanks again master !!
You nailed it. A crystal clear explanation.
I just can't stop watching you! Keep it going :)
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 👍🏻
John your videos are amazing and helping me so much with my studies in software development!
Keep doing what you are doing!
Thanks for making this concept much more understandable
I love your videos, straight on point and easy to understand.
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..
You're a gem. Keep going brother. Subbed.
I have never seen a tutorial like this. Very cool
Your videos are so clear and concise, tysm!
you make everything clear and simple. Thank you!
You were so clear and easy to understand. Thank you.
I like the way you make every topic in java easy to understand. Please do more java videos
very good explanation. i wish real life scenarios were as easy
I like ypu channel very much!!! You are my favorite englishspeaker youtube bloger, who makes Java Tutorials!!!
you explain the subject like it is very simple, then I open the examples that my teacher write, everything becomes hell again
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.
정말 좋은 수업 매일 매일 듣고 있습니다. 감사합니다. SUper easy to study.
Thanks a lot, John. You're really my saver there on my way to master Java !!!
This is very useful! Thank you for making this video!
Hey John, at 7:36 you showed a while loop. My question is that if there are 2 paragraphs, then wouldn't the reader just stop at the last line of the first paragraph and not further move on to the first line of the second paragraph?
It reads the line until there is no more lines
Thank you! John . For being my compiler .
Your videos are always needed. Thanks
It's better to use try with resources because close() may not get called if the readLine() or write() throws an exception
John, this is awesome! I really appreciate this tutorial.
Very Helpful Video. Please do a video on Serialization and De-serialization in JAVA with relevant examples. Thanks
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());
will there be any performance issues if we use this
@@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.
You awesome man, that was super easy to follow!
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.
thank you, that was super easy to follow
Liked, shared, subscribed, commented... Loving your content, thank you!
Every youtuber needs to know your location lol
great job, u made it looks so simple!! love it
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.
Super method of teaching,able to understand hard concepts though..
I just found my Java tutor, thank you God
Can you please create a video to compare ip/Op .xls file with some transformation logic applied.
Watching this for advent of code. Thanks!
Update: I can't do it. 😢
clear, concise and honestly reminds me that Java can be easier to manage than C
It's been about 15 years since I've needed to code in C and I can't say I've missed it
@@CodingWithJohn haha
Greatly explained....Need more contents ! :D
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
logical stuff in a few minutes. nice work
First of all, this is a great video but I have a problem: how can I write to a File without deleting anithing that was in the file previosly?
Use this code. Pass output file name as well as "true" parameters for the file writer object. The true signifies boolean "append" = true.
BufferedWriter writer = new BufferedWriter(new FileWriter ("Output.txt", true));
This video deserves more views!
John, god bless you! You are a amazing teacher!
Your tutorials are amazing, thank you so much!
Thanks a lot, John. Quickly and clearly)))
cant you throw an ioexception instead of a try catch ?
also is it okay to use a hasNextLine in the while loop?
thanks John, what a smooth explanation, i got it)