Results 1 to 11 of 11
  1. #1
    hongan is offline Member
    Join Date
    Sep 2008
    Posts
    6
    Rep Power
    0

    Default How to get value number from text file?????

    "write a project with GUI, allow user choose a txt file(use JFileChooser). In the txt file has values separated with semicolon ( ; )
    Example: 1;4;7;8;33;22;67;44;12;34;12;33
    After loaded, show the Prime numbers and count sum of them."


    I'm using Netbean 6.5.
    Please help me!!!!!!!

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    What you have done upto now?

    First you have to read the file into a string, may be. Then find all numbers there. And then do the rest.

  3. #3
    hongan is offline Member
    Join Date
    Sep 2008
    Posts
    6
    Rep Power
    0

    Default

    Can you show me some code lines example??

  4. #4
    hongan is offline Member
    Join Date
    Sep 2008
    Posts
    6
    Rep Power
    0

    Default

    It is easy to only write and read data from txt file. But i don't know how to convert that data to number. Is it saved as string?? It also separated by semicolon ";"...

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Is this your first Java application? If so, better to try something yourself first. At least read some examples on the web. Start from the GUI.

  6. #6
    hongan is offline Member
    Join Date
    Sep 2008
    Posts
    6
    Rep Power
    0

    Default

    I have write some projects about Input Output Stream. It's simple to store data in a file a load that file (txt). But this... how to get value(number format) from txt file like above??? Because i think it is string, isn't it?

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Ok, seems to me you can read the text file and get a string. Now question is how to separate them depends on the ; sign. Split the string. You can do it in this way simply.

    Java Code:
            String str = "1;4;7;8;33;22;67;44;12;34;12;33";
            String[] val = null;
            val = str.split(";");
            for(int i = 0; i < val.length; i++) {
                System.out.println(val[i]);
            }

  8. #8
    hongan is offline Member
    Join Date
    Sep 2008
    Posts
    6
    Rep Power
    0

    Default

    Thanks. I hope it'll work.

  9. #9
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  10. #10
    hongan is offline Member
    Join Date
    Sep 2008
    Posts
    6
    Rep Power
    0

    Default

    I have try your code and it works really good. But i have not finish my project yet. Thank you for your helping, Eranga. Maybe i'll ask you more.

  11. #11
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Fine, I'll help you anytime, but you have to try something first. Don't ask to write code for you. :)

    And also don't change the font color time to time. It can be difficult to read in colorful way. Use only one color as you wish.

Similar Threads

  1. count character in text file as input file
    By aNNuur in forum New To Java
    Replies: 7
    Last Post: 03-25-2010, 05:01 PM
  2. find and replace text from a text file
    By gezzel in forum New To Java
    Replies: 2
    Last Post: 09-19-2008, 05:04 PM
  3. read the file from different line number
    By vaskarbasak in forum Advanced Java
    Replies: 3
    Last Post: 06-02-2008, 02:31 PM
  4. How to read a text file from a Java Archive File
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-08-2008, 10:13 AM
  5. Converting text file(.txt) to JPG file(.jpg) in java
    By javadeveloper in forum Advanced Java
    Replies: 0
    Last Post: 11-09-2007, 05:22 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •