Java File class 📁

แชร์
ฝัง
  • เผยแพร่เมื่อ 5 ต.ค. 2024
  • Java File class tutorial example
    #Java #File #class #tutorial #example
    import java.io.File;
    public class Main {
    public static void main(String[] args) {
    // file = An abstract representation of file and directory pathnames
    File file = new File("secret_message.txt");
    if(file.exists()) {
    System.out.println("That file exists! :O!");
    System.out.println(file.getPath());
    System.out.println(file.getAbsolutePath());
    System.out.println(file.isFile());
    file.delete();
    }
    else {
    System.out.println("That file doesn't exist :(");
    }
    }
    }

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

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

    Hey bro, I just got a 97% on my final in my Java class and I wanted to say THANK YOU for helping to make that happen.

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

      good work!

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

      did you copy from google ?? xD

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

      Congratulations! Onward you go!👏

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

      My physics teacher was famous for saying, "Everything technical is not difficult, and everything difficult is not technical." I chewed on that for years. I think what he meant was to look for easy ways to solve problems when it's the right thing to do. Files are just files. A short video tuutorial is enough. Make it easy on yourself, because non-technical challenges await. Take care

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

    We love seeing a file in his desktop saying nuclear launch codes 😂

    • @zai_ry11
      @zai_ry11 8 หลายเดือนก่อน +1

      bro 😂

    • @affable.pebble
      @affable.pebble 2 หลายเดือนก่อน

      💀

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

    This playlist was really helpful. You made it easy for us without consuming a huge amount of time.

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

    If I use the relative filename , the java can't find that txt file .
    There are 3 solutions
    1) type "src\\message.txt" or "src/message.txt" .
    2) Change the eclipse working directory to the absolute pathname of the folder (src) that contains your packages and txt file .
    By doing that , you can click section in top bar [Run] -> [Run Configurations] -> [Arguments] -> [Working directory] -> change from [Default] radio button to [Other] , enter your absolute pathname after [Other] -> [Apply] -> [Run]
    3) type the absolute pathname .

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

      How do i find my absolute pathname??

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

      @@flick4556 right-click the txt.file in eclipse -> [properties] -> location

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

    NOTE: if file.exists() always returns false, make sure to inclute /src before the name. For some reason java thinks that main.java is in the project folder when its actually in /src.

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

      That just helps me

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

      isn't it src/ and not /src?

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

      @@WorstDruidEU yeah lol i was really confused for quite a bit

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

      System.out.println("YOU ARE THE MAN, MAN!");

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

      thank you so much

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

    What a useful programming video, and by a person who actually talks english!
    Amazing.

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

    import java.io.File;
    public class Main {
    public static void main(String[] args) {

    // file = An abstract representation of file and directory pathnames

    File file = new File("secret_message.txt");

    if(file.exists()) {
    System.out.println("That file exists! :O!");
    System.out.println(file.getPath());
    System.out.println(file.getAbsolutePath());
    System.out.println(file.isFile());
    file.delete();
    }
    else {
    System.out.println("That file doesn't exist :(");
    }
    }
    }

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

    This helped more than you could understand, thank you!

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

    Thank you sir you are the most amazing teacher I've ever seen 👍

  • @dianamilenaarchilacordoba4632
    @dianamilenaarchilacordoba4632 19 วันที่ผ่านมา

    great video!!! I'm infinitely grateful for your dedication and big heart to share this knowledge with the world. Thank you soo much

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

    Nuclear launch codes 🤣 I had a good laugh now.

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

    "Please excuse the mess".
    Me:**starts breathing heavily knowing I have over 50+ files on my desktop**

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

    So, as some people have already pointed out.
    Sometimes you need to enter the complete path for the file.
    You can see what that path is by right-clicking the file in the project tree and choose "Properties".
    Then copy all of that and use it instead of just the file name.

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

      That just helped me now😭😭. Thank you unknown helper 💗💗

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

    Keep your text file outside your src folder incase if file.exists() always returns false...

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

    WE back at it again, epic vid homie

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

      let's gooooooooo

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

    Thank you for this very useful video!

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

    Hey, Thank you for the awsome learning experience... You've been a great help through my Java class this term. :)

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

    اقسم بالله عظمة !!

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

    Awesome video, I love the way you explain new concepts

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

    Waiting for DataStructure in java full Video , Please keep going, and thank You.

  • @nimbcorp
    @nimbcorp 26 วันที่ผ่านมา

    good one, nice video.

  • @affable.pebble
    @affable.pebble 2 หลายเดือนก่อน

    Cool! Easy to follow

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

    Love your videos! Everything becomes so easy

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

    Here's a prayer to the youtube algorithm. :D Thank you Bro Code for amazing videos!

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

    I find these videos so helpful. One problem I have with files though is when I make an installer for an application which allows a user to define where they want to install to, how can I set that file path then back in the application so it reads and writes to that file?

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

    Thank you Bro code !!! Appreciate your work man ... Keep up the good work .

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

    He is a legend,gamer+programmer

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

    Best TH-cam teacher ever

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

    Thank you for all your work on these videos

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

    Hey i got a problem with my Intelidea that the program doesn't recognize the file for an unknown reason, showing on console that file doesn't exist...
    Only when i put full path, than all works fine..

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

      yes it happens for me too! i'm using linux so maybe it has something to do with that..... idk

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

    love your technique
    bro

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

    I am loving with bro code for his coding content.

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

    thanks very nice vid & explanation

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

    Thanks, Bro! ☕ You're awesome!

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

    Thanks Bro for this awesome videos, stop making Java easy to understand

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

    Thanks! Cramming and my prof didn't cover this topic :/

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

    I don't quite understand the file.delete part. Shouldn't the program every time you start it create a file (File file = new File("poem.txt");) , so eventually only the first condition of if statement (file.exists()) would be fulfilled. I know the file gets deleted by the end, but with another start of the program it is created again. So like, why every other start of the program ignores the File file = new File(); line.

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

    beautiful work my lord

  • @philosyche
    @philosyche 2 วันที่ผ่านมา

    thank for this

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

    Dude you are amazing!

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

    nice

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

    super helpful, thanks bro

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

    thakyou so much for the videos

  • @ABC-zv1sd
    @ABC-zv1sd 2 ปีที่แล้ว

    Hello,
    I am developing android java filemanager app.. I used checkbox to check 1/file.mp4
    2/folder(files+sub folders)
    .
    How can i add copy paste feature for checked 1, 2 file folder fully at same time ?like -google filemanager app..
    Advance Thanks

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

    Short N Sweet

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

    sheiii bro

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

    love the easter eggs

  • @wombozombo
    @wombozombo 2 วันที่ผ่านมา

    💪

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

    super

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

    Thanks a lot!

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

    You are just awesome 😎

  • @曾毓哲-b1t
    @曾毓哲-b1t ปีที่แล้ว

    Thank you very much

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

    Hello , i have a question please , i did all the instructions but it shows no file for some reason , why is that ?
    Edit: its ok comments already answered that , keep the great work man

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

    thanks! really well explained!

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

    Thank you so much sir.

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

    Amazing bro!

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

    Bro I learn a lot from you thank you

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

    Just the best

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

    thanks

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

    Simply superb👍

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

      thanks for watching Lakkoju!

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

    keep the good work up brother

  • @adeelahmaddev.9346
    @adeelahmaddev.9346 3 ปีที่แล้ว

    Great!

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

    you are realy helpful bro. :)

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

    Thanks bro.

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

    nice video

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

    thank you bro

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

    nice video buddy...

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

    who can resist this thumbnail

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

    Good video!!

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

    best brooo

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

    I do have a file but it won’t full the array

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

    Thanks

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

    thank you, you are the best : >

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

    Thanks, Bro!

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

    Don't we have to close the file afterwards?

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

    thanks bro

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

    best bro ever!

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

    i'm hungry

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

      still hungry?

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

    Bro i just want u to know; you re saving my ass ! thank u soo much !!!

  • @Roldan-zs7nq
    @Roldan-zs7nq 5 หลายเดือนก่อน

    I love you bro

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

    Goat

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

    😇❤

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

    can i have the Nuclear launch codes pls AHAHAHA

  • @Abaddon-u1i
    @Abaddon-u1i 3 หลายเดือนก่อน

    Thank you bro, comment for the bro code

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

    EPIC

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

    dude you live in my heart S2

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

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

    nice 2.0

  • @GOODBOY-vt1cf
    @GOODBOY-vt1cf 3 ปีที่แล้ว +1

    4:38

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

    hey bro can you paste the code in the comment

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

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

    nuclear launch codes... 💀💀💀💀💀💀

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

    come on bro we want spring framework and spring boot

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

    "NUCLEAR LAUNCH CODES" XDDDDDDDDDDDD
    i wanna know what the fuck exactly resides in that XDDDDDDDDDDDDDDD

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

    import java.io.File;
    public class Main
    {
    public static void main(String[] args){
    File file = new File("song_lyrics.txt");
    if(file.exists()){
    System.out.println("That file exists! :O!");
    System.out.println(file.getPath());
    System.out.println(file.getAbsolutePath());
    System.out.println(file.isFile());
    file.delete();
    }
    else{
    System.out.println("File does not exist");
    }
    }
    }

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

    Watch now

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

    I click your ads bro !!

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

    Add a public comment...

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

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

    A comment