Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Saving to a text file

  1. #1
    Junior Member PsYNus's Avatar
    Join Date
    Sep 2011
    Location
    Johannesburg, South Africa
    Posts
    10
    My Mood
    Inspired
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Saving to a text file

    I'm not yet fully up to speed with the logic of how to write to a text file.
    The program that I am trying to write will save a whole list of chars and their ASCII value (value up to 1000). I want to save the output to a text file as it has unicode so I will be able to see what the symbols are (when eclipse returns the values the symbols show as a ?).
    Would any1 be able to suggest to me a link to visit to read up on this or are there any suggestions as to what I should do?

    [here is my code]
    package testPackage;
    import java.io.*;
    import java.math.BigDecimal;
    import java.nio.charset.Charset;

    public class CharListLoopToTxt
    {
    public static void main(String[] args)
    {
    for(int i = 0; i<1000; i++)
    {
    char charLoop;
    charLoop = (char) i;
    BigDecimal rr = new BigDecimal(charLoop);
    Charset charset = Charset.forName("US-ASCII");
    String s = "";
    try (BufferedWriter writer = Files.newBufferedWriter(file, charset))
    {
    writer.write(s, 0, s.length());

    }

    System.out.println(rr +" is the ASCII value for "+ charLoop);

    }
    }
    }

    Again I am not yet fully up to speed with the logic of how to write to a text file so just bear that in mind :p


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Saving to a text file

    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Saving to a text file

    I want to save the output to a text file as it has unicode so I will be able to see what the symbols are
    What program are you using to look at the text file? That can determine what you see in its display.
    On Windows have you ever created a Unicode text file using Wordpad? Try it and then look at the first bytes of the file. There are some flag bytes there that tell Wordpad about the file's contents.
    For example,here is a text file (split into 4 char units) in Unicode format:
    FFFE 5400 6800 6900 7300 2000 6900 7300 2000 7500 6E00 6900 6300 6F00 6400 6500 2E00

  4. #4
    Forum VIP
    Join Date
    Oct 2010
    Posts
    275
    My Mood
    Cool
    Thanks
    32
    Thanked 54 Times in 47 Posts
    Blog Entries
    2

    Default Re: Saving to a text file

    Wow I did not know of the Files class.. thanks for making me google it They finally made a set of helper methods xD

Similar Threads

  1. Replies: 3
    Last Post: February 21st, 2011, 07:25 PM
  2. Saving a file using a dialog box
    By Deprogrammer in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 5th, 2010, 05:21 PM
  3. saving xml file
    By LOL in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 18th, 2010, 05:45 AM
  4. java program to copy a text file to onother text file
    By francoc in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: April 23rd, 2010, 03:10 PM
  5. [SOLVED] Saving A File?
    By MysticDeath in forum File I/O & Other I/O Streams
    Replies: 0
    Last Post: August 1st, 2009, 11:56 AM