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 7 of 7

Thread: Suggestions about best way to export/inport data to a .txt file

  1. #1
    Junior Member
    Join Date
    Dec 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Suggestions about best way to export/inport data to a .txt file

    Okay, I am putting together this program and need some suggestions on the best way in Java to export data to a text file (2 dimensional array), that can later be recalled. The program is designed such that the user enters in how many hours they worked and how much they charged per hour. This information is displayed in a jtext area, but I also need it to write the information into an array. Since the data is dealing with hours and money, the data type needs to be numeric. It is also very critical that the array is a .txt file, not an .xml file. The program has a second function which is to allow it to call the information from the array. My question though is what is the best way to export the data from the jtext area to the .txt file. A friend of mine suggested using stringbuilder. I am just looking for the most efficient way.


  2. #2
    Member snowguy13's Avatar
    Join Date
    Nov 2011
    Location
    In Hyrule enjoying a chat with Demise and Ganondorf
    Posts
    339
    My Mood
    Happy
    Thanks
    31
    Thanked 48 Times in 42 Posts

    Default Re: Suggestions about best way to export/inport data to a .txt file

    JTextArea's getText() method may be helpful for retrieving text. As for storing information in a .txt file, I'd look at the PrintWriter class. For reading data from a .txt file, you may want to check out the FileReader class. That would be appropriate if you are only using text and simple characters to store data. To be more specific (which I don't think you'll need) you may want to specify a InputStream (use one of its subclasses).
    Use highlight tags to help others help you!

    [highlight=Java]Your prettily formatted code goes here[/highlight]

    Using these tags makes your code formatted, and helps everyone answer your questions more easily!




    Wanna hear something funny?

    Me too.

  3. #3
    Member
    Join Date
    Dec 2011
    Location
    United States
    Posts
    94
    My Mood
    Amused
    Thanks
    5
    Thanked 8 Times in 8 Posts

    Default Re: Suggestions about best way to export/inport data to a .txt file

    This might not be part of the suggestions but instead of employing a 2 - dimensional arrays with two fields, wouldn't it be easier to use the Java Collection Framework's Maps? Just asking because I am trying to learn too. Thanks for the question. On another note, what scenarios will prompt you to use 2-dimensional arrays rather than either lists or Maps?

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Suggestions about best way to export/inport data to a .txt file

    I am just looking for the most efficient way
    Most efficient and best way are relative (and often alternatives work just fine). My recommendation: write the data to a file as you see fit and understand, and read said data as needed. If needed, make up your own file format (or use Serialization).

    You do not provide code or a basis of what you know, so if you are unfamiliar with how to do this I suggest reading the following: Lesson: Basic I/O (The Java™ Tutorials > Essential Classes), and of course should you run into problems then by all means just ask another question.

    Once you have a working solution you will be able to determine if it is efficient, perhaps compare it to alternatives.

  5. #5
    Junior Member
    Join Date
    Dec 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Suggestions about best way to export/inport data to a .txt file

    snowguy13, Thanks for the suggestions. I will look into these although I don't think the InputStream is what I'm looking for either. Copeg, I would have included some code with it, however, this project is in the conceptual stage right now so there is no code written as of yet (other than a generic framework that has the text fields and the input button). I have a decent understanding of Java and I guess I should have been a little more clear when I posted my request. Instead of saying most efficient or best way, I should have just asked for some general ideas on ways to do it. The guys wanting this done really don't care, they just want it to take input from the JText fields and store them in the 2D array, then be able to recall that information at a later date. Thanks for the suggested reading.

  6. #6
    Junior Member
    Join Date
    Oct 2013
    Location
    Atlanta
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Suggestions about best way to export/inport data to a .txt file

    What type of database are you using?

  7. #7
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Suggestions about best way to export/inport data to a .txt file

    @Vertisys, please note that the date on this thread is over a year and a half old.

Similar Threads

  1. Replies: 1
    Last Post: April 7th, 2011, 07:01 AM
  2. Replies: 8
    Last Post: March 25th, 2011, 02:34 PM
  3. Using File Data
    By computercoder in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 18th, 2010, 07:51 PM
  4. How to export data from web page to msword or pdf
    By verma86 in forum JavaServer Pages: JSP & JSTL
    Replies: 1
    Last Post: April 6th, 2010, 05:49 AM
  5. Export to excel
    By ebosysindia in forum File I/O & Other I/O Streams
    Replies: 7
    Last Post: May 14th, 2009, 06:25 AM