Results 1 to 5 of 5
  1. #1
    mark-mlt is offline Member
    Join Date
    Apr 2008
    Posts
    15
    Rep Power
    0

    Default sorting problem...

    Im trying to load data from a text file ghax display it in a text area and load the contents of the file in alphabetical order; the following piece of code which i cant get working; any one can help pls!


    ------------------------------------------
    private void test() {
    {

    try {
    in = new BufferedReader(
    new FileReader(
    new File(
    "C:\\test.txt")));

    // Declare Array which will hold 10 lines
    String[] myarray;
    int n = 10;
    String lineContent = null;

    myarray = new String[n];

    // Read each line into the array
    for (int i = 0; i < myarray.length; i++) {
    myarray[i] = in.readLine();

    int currentLine = 0;
    // this will be set to true if the string was found
    while (true) {
    currentLine++;
    // get a line of text from the file
    try {
    lineContent = in.readLine();
    } catch (IOException e) {
    break;
    }



    String str = null;// = lineContent;
    StringTokenizer st = new StringTokenizer(str);

    if (st.countTokens() > 1) {

    System.out.println("Number of Words: " +
    st.countTokens() );
    Arrays.sort(myarray);
    System.out.println("Sorted Strings: " + "\n"+ Arrays.asList(myarray)+"\n");}

    }
    }
    }



    catch (IOException e) {
    lineLabel.setText("Error Opening Text File");
    JOptionPane.showMessageDialog(null,
    "The File cannot be opened.", "Information",
    JOptionPane.INFORMATION_MESSAGE);

    }
    }

    }

    --------------------the end -------------

  2. #2
    mark-mlt is offline Member
    Join Date
    Apr 2008
    Posts
    15
    Rep Power
    0

    Default

    no helpp?? :S

  3. #3
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    And what is you problem?

    regards,
    sukatoa

  4. #4
    mark-mlt is offline Member
    Join Date
    Apr 2008
    Posts
    15
    Rep Power
    0

    Default

    its not working ...

  5. #5
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

Similar Threads

  1. Sorting JTable (Vectors) Problem
    By ramapple in forum AWT / Swing
    Replies: 6
    Last Post: 07-06-2009, 11:15 PM
  2. sorting problem
    By mcal in forum New To Java
    Replies: 1
    Last Post: 02-14-2008, 08:13 AM
  3. Problem with sorting Table
    By sireesha264 in forum Advanced Java
    Replies: 0
    Last Post: 02-08-2008, 02:21 PM
  4. Heap Sorting
    By kesav2005 in forum New To Java
    Replies: 1
    Last Post: 11-13-2007, 04:04 PM
  5. sorting JTable
    By mansi_3001 in forum Advanced Java
    Replies: 3
    Last Post: 08-10-2007, 06:29 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
  •