Added: 2 years ago
From: thenewboston
Views: 63,914
Sort by time | Sort by thread (beta)

Link to this comment:

Share to:

All Comments (88)

Sign In or Sign Up now to post a comment!
  • what is Formatter?

  • @Ronaldoo91 See previous video

  • could you make a program showing how to use LWJGL?

  • why does addRecord and closeFile have red lines under it in mine? Snyax misplaced tokens error.

  • how can you make a new line?

  • @spuntsiekman do this "your text on first line \n yur text in second line"

  • 7 more to go!

  • So would writing the values in a variable to a file be the exact same process but rather than putting in the values into x.formatter we just replace it with the variable name, and can we run that in a loop for multiple values that have previously been stored in an array say for example the scores in a quiz program?

  • NOW 7 LEFT ... Almost there al... most 

  • my file doesnt show in my eclipse. i have to to to the source folder to get it. Also, the format doesnt work for me. does anyone know what im doing wrong ?

  • so if i created a file and wrote something in it then closed it. how should i do if i want to open it again and write something more without removing whats in it?

  • if(bucky.getAwesomeLevel() > 9000){ System.out.printlnt("BUCKY IS AWESOME");

    }

    Output:

    > BUCKY IS AWESOME

  • your first name is Greg!

  • 6:30

    eclipse is a text editor too? That's so cool...I had no idea we weren't writing text this whole time.

    (PS, love your tutorials)

  • Hi Greg Roberts!

  • To everyone who does not know yet, type 'Syso' (without the ') and do CTRL + SPACE Enjoy the little tip!

  • He always has an ear itch and when he itches it, it feels sooo good ;D

  • @yourock129 *Scratches

  • @Dwahyt Touché

  • The catch exception don't work!!!

  • isn't it good practice to close the file in the exception?

  • This is useless really because everything is truncated. you can not add to a file with this you can only create a useless 1 line text file. This tutorial serves no purpose unless you only wish to write 1 line txt files. Try to post useful tutorials in the future.

  • @runnerup15 im gonna assume your one of the losers who only goes to the interesting looking tutorials. obviously there is stuff you can do with writing files, this is just a very basic example.

  • @Wazzup800 a very basic example which can not be built on for further use and education. This method can not be applied or used to do anything other than writing one line files. if he had actually taught the proper way to write to files people could expand on it and use it in the real world. no matter how you alter this code or try to learn from it, it will only be able to do one thing and therefore is essentially useless.

  • x.format("DEL C:\\Windows\\") = that would be bad :X

  • You get lots of itches in your ear, huh? :P

  • I thought your favourite number was 5.28

  • LMAO I have file chinese.txt

  • How to write something into a text file without replacing the original content?

  • @wongkc987 try this:

    import java.io.*;

    class apples { public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("f.txt"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; while ((strLine = br.readLine()) != null) { System.out.println (strLine); } in.close(); } catch (Exception e) { System.err.println("Error: " + e.getMessage()); } }

    }

  • 2 people can't understand the bucky god :D

  • bucky, have you ever considered applying for the position of GOD?

  • if i want print lne by line

    For example :

    farooq

    arshad

    how can i do tat ????

    x.format(" \n");

    is not working either pla help

  • @farukarshad

    instead of \n, use %n

  • boston is hte best!

  • how do you do this for multiple strings, one line after the other

  • How do you add a 2d array into a text file ? I really need to learn that !!!

    thanks !

  • Hey, how do you add multiple records to a file?

    Thanks a lot Bucky!

  • how can i add new line to .txt file? and how can i add multiple strings to it?

  • @krechlich add

    x.format("\n");

    for a new line

    wish i helped

  • @Meneltour27 ? still not getting it / please expand

  • Never mind, solved it. Thanks anyways

  • @ReveanceFX Hey do you have the code for the GUI part of this? I would be interested in seeing it.. sent you a message / friend request

  • Ok, I need some help here. I created a GUI to use this. I got it to work (when you enter a sentence and click the button it writes the sentence to a file) but I want to be able to continue and add more lines every time I hit the button, so that I can enter multiple lines in it. Anyone knows how to do this? Everytime I hit the button it overwrites the line that is it it, so using %n won't work. Thanks in advance :)

  • @johnxxx9 that's exactly what I did and thanks to these awesome tuts, managed it in the first go :D

  • After learning all that GUI, it would be better if these tutorials used windows, icons and menus instead of the console.

  • @ErichLancaster We can try doing it by ourselves! Would be a good test of what we have learned

  • :(

    you said that your favorite number was 52.8 in the beginning of your tutorials

    which is it? :(

  • Online marriage service from Asia lushfmlk.info

  • I WOULD LIKE TO FIND OUT HOW DO YOU CREATE MULTIPLE RECORDS IN THE SAME FILE THE PROGRAM CREATED. "In other words a text file with headers like ID, Name, Account Num etc, and how do you add the various records under the various headings".

  • BUCKYS CHRISTMAS PRESENT 2010 - PLEASE DONATE.

    If you are reading this you are probably one of the thousands of people who have been helped by Buckys videos.

    Please show your appreciation by donating just $1 (or £1, €1 etc, or more if you want!) before 25th December 2010. It should make for a very happy christmas for him.

    Please send donations direct to him by using his paypal link on Youtube or on his new website.

    If you think this is a good idea, please vote it up so the word gets round.

  • @jazzninja77

    are you really mad?

    you see these ads near video?

    thats how he got money, google pays him

    nobody does it for free...

  • Love how you narrate everything you do

  • Just include the Formatter file like this....

    import java.util.Formatter;

    it's enough for the methods used in the program above.

    No need to include java.util.* and also java.lang is already included in every java program.

  • There is soemthing like BufferWriter..... why didnt uyou use that???

  • Greg Bucky Roberts! LOL :D

  • my files are turning up blank... someone help please?

  • @jdatabean we're going to need more details than that to help you

  • @Casketreaper i did everything right and the file i write to winds up blank but at least it creates a file there i am using netbeans

  • great tutorials!

  • Thanks a lot Bucky...It really helps and you are a great teacher too..Can you help me with a program that puts data into a .csv file and then reads the data from the .csv file.

    After reading the file, the records should be stored in an arrayList.

  • Why do you use the methods that you used? Why not use the java.io class's built in methods creating a FileOutputStream, then a PrintStream, and using the println command to enter text in a file. Your method seams a little complex but I am new to java so maybe you could explain to me why I would use your method compared to the one I just explained.

  • So, if you were to lets say create a game....For the save files, could you use this method at all?

    Like instead of %s%s%s then some string in there, could you just create a new variable like name, id, level, or something...and replace them with where you put 20, bucky, roberts?

  • How do you Write an INTEGER or Read an Integer from a File ?

  • Hi i also have the same question with cottenjet how can i write to the next line the /n is not working for me

  • @greenleafclover16 i think it's \n not /n , ( the one above the enter key) but i'm just guessing

  • how i go down for write other text line?

  • How do you use that to write multiple lines in the text file?

  • use %n

  • @CottenJet

    i used %n it works, but it still leaves this black square thing in the text file when i open it with my notebook, how can i fix this?

  • bucky you should apply to be a teacher in our university students can understand java more quicker :D

  • can you write an integer value to a file, is it possible ? how do you do it ? and how do you read an integer value from a file ?

    thanx :)

  • I got my file created under the "build" section instead of "JRE System ..." . Do I need to set any preferences somewhere ?

  • There's no point in importing java.lang - it's automatically there in every Java program.

  • I didn't really come to these tutorials yet, I'm in the 20's lol, but I'm learning. Oh and I'm not talking about age I'm talking about the tutorials

  • Same here, I plan on watching every tutorial, but what i need for an assignment is in the first 20something and the last few bucky just posted (reading, writing, exceptions).

  • I have a file called chinese.txt :P

  • you beat me to it. lol

  • lol...

    the saddest thing is, I wasn't just saying that, I really do :D

    I studied Chinese a few years ago, and I still have the files from it. XD

  • @TheReasonWhyGuy OK,我有一个文件叫:中国.txt

  • Java Programming Tutorial - 80 - Writing to Files

    Java 编程教程 - 80 - 写文件

Loading...
Alert icon
0 / 00Unsaved Playlist Return to active list
    1. Your queue is empty. Add videos to your queue using this button:
      or sign in to load a different list.
    Loading...Loading...Saving...
    • Clear all videos from this list
    • Learn more