Java FileReader (read a file) 📖

แชร์
ฝัง
  • เผยแพร่เมื่อ 5 ต.ค. 2024
  • Java FileReader how to read a file tutorial example
    #Java #FileReader #read #file #tutorial #example
    public class Main {
    public static void main(String[] args) {
    // FileReader = read the contents of a file as a stream of characters.
    //read() returns an int value which contains the byte value
    //when read() returns -1, there is no more data to be read
    try {
    FileReader reader = new FileReader("art.txt");
    int data = reader.read();
    while(data != -1) {
    System.out.print((char)data);
    data = reader.read();
    }
    reader.close();
    } catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }
    }

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

  • @BroCodez
    @BroCodez  4 ปีที่แล้ว +55

    public class Main {
    public static void main(String[] args) {

    // FileReader = read the contents of a file as a stream of characters. One by one
    // read() returns an int value which contains the byte value
    // when read() returns -1, there is no more data to be read

    try {
    FileReader reader = new FileReader("art.txt");
    int data = reader.read();
    while(data != -1) {
    System.out.print((char)data);
    data = reader.read();
    }
    reader.close();

    } catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }
    }

    • @oguzhantopaloglu9442
      @oguzhantopaloglu9442 4 ปีที่แล้ว +3

      Hey bro can you make a tutorial on playing sounds in java? I want to add some music and sound effects to my GUI...

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

      Love this channel.

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

      Thank you so much for this tutorial.
      Your code does not work.:(
      Here is mine:
      import java.io.FileReader;
      import java.io.IOException;
      public class Main{
      public static void main(String[] args){
      try{
      FileReader reader = new FileReader("lyrics.txt");
      int data = reader.read();
      while(data!=-1 ){
      System.out.println((char) data);
      data = reader.read();
      }
      reader.close();
      }catch(FileNotFoundException e){
      e.printStackTrace();
      }catch (IOException e){
      e.printStackTrace();
      }
      }
      }
      There's also an issue with my code.
      I get this error message:
      "error(s).Main.java:17: error: cannot find symbol
      }catch(FileNotFoundException e){
      ^
      symbol: class FileNotFoundException
      location: class Main
      1 error"
      If anyone knows how I can fix my code, kindly let me know.

    • @Chan-he8sk
      @Chan-he8sk ปีที่แล้ว +1

      @@joyceasante8292 i think you forgot to add
      import java.io.FileNotFoundException;

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

      Issue fixed! Thanks@Chan.
      import java.io.FileReader;
      import java.io.IOException;
      import java.io.FileNotFoundException;
      public class Main{
      public static void main(String[] args){
      try{
      FileReader reader = new FileReader("lyrics.txt");
      int data = reader.read();
      while(data!=-1 ){
      System.out.println((char) data);
      data = reader.read();
      }
      reader.close();
      }catch(FileNotFoundException e){
      e.printStackTrace();
      }catch (IOException e){
      e.printStackTrace();
      }
      }
      }

  • @caidenhiles
    @caidenhiles 11 หลายเดือนก่อน +4

    Your videos are so helpful bro. Not only do your videos make so much more sense than any googling or even courses I can take, but you make so many of them and you even copy your code down in the description?! You definitely make the best coding tutorials out there. Thank you for the hard work and dedication!

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

    He makes Java very easy to understand thanks bro keep writing code!!!

  • @davidmonsalve8525
    @davidmonsalve8525 3 ปีที่แล้ว +4

    Bro, ill never get tired of saying you're the besssssssssssssst.

  • @abhijitbaral9283
    @abhijitbaral9283 4 ปีที่แล้ว +7

    thanks for the video bro..
    i had no idea about ascii art

    • @BroCodez
      @BroCodez  4 ปีที่แล้ว

      You can write some text too. I thought the art would be fun

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

    Am I the only one who noticed that in 1:28 our bro has the Nuclear lunch codes folder ? ahahah

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

    Nice short of video, easy to learn. 👍👍

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

    Really amazing work!

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

    Leaving a comment for the algorithm

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

    gotta try catch them all. nice video bro

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

    Thank you for being on TH-cam. Your saving me while I take 261 ❤😂😅

  • @saifmhosen1291
    @saifmhosen1291 4 ปีที่แล้ว +3

    Can you make XML tutorials please?

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

    Bagus sekali penjelasannya. 👍👍😎

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

    Thank you for this very useful video!

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

    Tysm i'm going to my final exam with understanding from your codes

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

    I like my lectures like I like my beer: clear and inspiring

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

    cool stuff

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

    Watching this from Dhaka,Bangladesh.
    i have a request,bro.Please,make a video on how to securely Lock file (like zip-folder do) using java-swing (not just making the file read-only) & keep this good work continuously.

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

    Thanks bro. Simple and perfect explanation.

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

    this was helpful, thank you

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

    awesome🙌 thank you

  • @sihleeundefined1208
    @sihleeundefined1208 4 ปีที่แล้ว +5

    Yoh bro I've been meaning to ask, what is e.printStackTrace()?

    • @BroCodez
      @BroCodez  4 ปีที่แล้ว +5

      It will print the exception that occurs

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

    damn that ending HEY YOU got me
    LIKED

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

    Adding comment for support.

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

    Amazing vid

  • @danny.3036
    @danny.3036 3 ปีที่แล้ว

    Thanks, Bro! ☕ You're awesome!

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

    Nice, bro!

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

    Great and simple

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

    Круто! Я не очень хорошо знаю английский, но я все понимаю. Спасибо)

  • @Logeshwaran-t4z
    @Logeshwaran-t4z 4 หลายเดือนก่อน

    Happy brother's day bro

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

    Great video as always

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

    Thank you Bro from Morocco : )

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

    Hey man doubt you will see this, u have been very helpful to me, but this just wont work for me, it just keeps saying it cannot find the file. I have no idea what to do and I’ve been struggling in this 6 week summer class for college!

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

    awesome channel! thanks!

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

    Thanks again, bro 😎

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

    Thanks ;)

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

    ❤️❤️❤️❤️

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

    Thank you so much sir.

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

    I want to become a fellow bro

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

    Appreciated work❤

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

    Thanks, Bro!

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

    can't run even if i copy your program and created same file

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

      FileReader fr = new FileReader("C:\\Gfg.txt"); try giving full location

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

    Hyo Bro 👌, well simplified

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

      thank you Mon Wil!

  • @НікітаОрлов-с3ч
    @НікітаОрлов-с3ч ปีที่แล้ว

    Hi Brroooooo! You are the best

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

    Nice

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

    Amazing video, would you consider doing a json reader?

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

    Why reader.read(); didnt stop unless we put into data variable ?

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

    dope video

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

    Thanks bro!

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

    Thanks bro.

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

    U are a Hero

  • @Pink.Heartz
    @Pink.Heartz 2 หลายเดือนก่อน

    Chat bot Ai, you can literally……..🗣🔥

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

    Is nobody going to talk about the fact he has nuclear launch codes saved on his desktop?

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

    super

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

    thanks

  • @pa-305
    @pa-305 3 ปีที่แล้ว

    best broo

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

    thanks bro

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

    Thank!

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

    nice vid

  • @MrLoser-ks2xn
    @MrLoser-ks2xn 2 ปีที่แล้ว

    Thanks

  • @augischadiegils.5109
    @augischadiegils.5109 3 ปีที่แล้ว

    Thanks bro

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

      thanks for watching chadie!

  • @omardumet120
    @omardumet120 4 ปีที่แล้ว

    💯

  • @علاءعبدالجواد-ي9ي
    @علاءعبدالجواد-ي9ي 3 ปีที่แล้ว

    THANKS ALOT )))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))

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

    nope all file video lessons not working :(, to bad this happens
    I follow step by step no file in java folder can be seeing but he there
    no output on console

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

  • @RaselAhmed-ix5ee
    @RaselAhmed-ix5ee 3 ปีที่แล้ว

    if i got a file , and it conatins the numbers as
    2, 57
    7, 78
    8,35
    how do i read the file and store the 1st and 2nd column in 2 different arrays? please reply its urgent

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

    anyone know why after i run this the image is shown for like a second and then it disapperead?
    i even tried it with bro's code and it didnt work

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

    Bro Code
    Can You Make A multi account login Form
    or registration form for console Tutorial?

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

    i have a problem in my eclipse the auto generated doesn't appear i have to write it anyone can help me

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

    gg

  • @Aliahmadi-fn5of
    @Aliahmadi-fn5of 6 หลายเดือนก่อน

    Yooooo😂

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

    why cant i use the read method

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

    ahhh it just shows a bunch of number instead of words

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

    One more to go to make this happen by doing code...

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

    I would like the video butt, u know, 420

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

    Bro? 😳

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

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

    but i dont pray

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

    Yo just wanna say that GOD loved the world so much he sent his only begotten
    son Jesus to die a brutal death for us so that we can have eternal life
    and we can all accept this amazing gift this by simply believing in him (Jesus) asking for the forgiveness of your sins
    and forming a relationship with heavenly father.

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

    drop a comment below!!

  • @antoinealam6531
    @antoinealam6531 24 วันที่ผ่านมา

    bro

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

    comment

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

    Not well explained for a beginner

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

      I don’t think it gets much easier than that, maybe you need to review some core concepts first.

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

    Read About Islam Bro

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

    😀

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

    Nice

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

    Thanks, Bro!

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

      free Palestine

  • @jo-de-uz
    @jo-de-uz ปีที่แล้ว

    thanks

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

    thanks bro

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

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

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

    thanks