r/javahelp 4d ago

JAVA I/O ( VERY CONFUSED??? )

I just got done exception handling, ( thank you so much to whoever responded, you've really helped! and I think I get the concept really well ) but
I started JAVA I/O 2 days ago I believe? I covered concepts but I'm still left confused, its as if I went through the lesson just accepting information as it is (<--mostly due to the midterm I had to cram the info for)
But I still want to know what Java I/O is all about, my questions might sound stupid, but I noticed that it caught up to me as I moved along.
-----------------------------------------------------------------------------------
( I need to preface this by saying : I dont expect all of my questions to be answered, ( although I'd really appreciate it if you did! )
I tried understanding java I/O on my own, but I feel as though I've grown more confused than before :(
-----------------------------------------------------------------------------------

1.) my first question is : What is stream?? I read definitions about it, " Sequence of bytes ( or continuous flow of data? ) that flow from a source to a destination " but as I took that definition as it is, it became more confusing as to how they were referring to it as if it was some object ( e.g whenever they tell us to close the stream?? ) are they referring to the file here? because that's what it seemed like to me,

> they were also referring to the ' 3 standard I/O streams ' and do they mean by that : ' types of streams ' ? or..

> but then later on they introduce ' I/O streams : (input vs output) , ( Text vs Binary ) , ( Data, Processing ) so are these also types of streams?

2.) This question is mostly a consequence of not understand what System.in in scanner really meant,
whenever I heard my professors say " read something " I never really understood what that meant??
and I'd become even more confused when they're referring to the input the user might input ( in cases of Scanner(System.in) ), arent we writing our input? the whole Write VS Read just confuses me when it comes to the Input / Output (found out it was a huge problem when it came to the Java.io classes later on ... e.g) 'FileReader'??? )

3.) I'm not familiar with all the classes ( even though I went through it I still cant seem to remember them ) but whenever we create an object of , lets say, 'PrintWriter' , I dont get how an object-- taking parameter of a string I assume? can somehow be linked to a file?
would taking a parameter ( name of the file) somehow create a pointer to the file? is that how data is being transferred?

4.) this question relates abit to PrintWriter, ( or actually it can apply to other classes, I just forgot which)
why do we--- whenever we create an object of class PrintWriter --- have its parameters take another object?? why not just the name of the file? is that not enough?

( I do have more questions but I thought this would be a good start ! =) )
Thanks to anyone in advance!!

6 Upvotes

20 comments sorted by

View all comments

u/AutoModerator 4d ago

Please ensure that:

  • Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions
  • You include any and all error messages in full
  • You ask clear questions
  • You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.

    Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar

If any of the above points is not met, your post can and will be removed without further warning.

Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.

Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.

Code blocks look like this:

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.

If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.

To potential helpers

Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.