×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    38

    what is wrong with the code?

    hi.i have developed a english-greek translator but i have a problem with showing up the greek characters.so i changed this part:
    public void loadData() {
    InputStream is = this.getClass().getResourceAsStream("/files/names.txt");
    int c;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
    while((c = is.read()) != -1) {
    if (c != '\n') {
    baos.write(c);
    }
    else {
    String s = baos.toString();
    decode(s.substring(0, s.length()-1));
    baos.reset();
    }
    }
    // Read ended
    if (baos.toString().length() > 0) {
    decode(baos.toString());
    }
    }
    catch(IOException ioex) {
    System.out.println("Problems while reading: "+ioex);
    ioex.printStackTrace();
    }
    }
    with InputStreamReader.so now my query manger is like this:

    package hello;

    import java.io.InputStream;
    import java.io.ByteArrayOutputStream;
    import java.io.IOException;
    import java.util.Hashtable;
    import java.util.Vector;
    import java.util.Enumeration;

    public class QueryManager {

    private Hashtable names; // Structure: key = String name
    // value = Vector Surnames (a vector of strings)

    public QueryManager() {
    names = new Hashtable();
    }

    static String readInput() {
    StringBuffer buffer = new StringBuffer();
    try {
    FileInputStream fis = new FileInputStream("names.txt");
    InputStreamReader isr = new InputStreamReader(fis,"UTF8");
    Reader in = new BufferedReader(isr);
    int ch;
    while ((ch = in.read()) > -1) {
    buffer.append((char)ch);
    }
    in.close();
    return buffer.toString();
    }catch (IOException e){
    e.printStackTrace();
    return null;
    }
    }

    private void decode(String s) {
    Vector surnames = new Vector();
    String name, surname;
    int firstSpace, space; // this will give us the position of the space string
    firstSpace = s.indexOf(" ");
    name = s.substring(0, firstSpace);

    System.out.println("Word: "+name);

    while ( (space = s.indexOf(" ", firstSpace+1)) != -1 ) {
    surname = s.substring(firstSpace+1, space);
    System.out.println("Answer: "+surname);

    // we add the surname to the surname vector
    surnames.addElement(surname);

    firstSpace = space;
    }
    names.put(name, surnames);
    // we add an entry in the hash table.
    }

    public String searchSurnames(String name) {
    Vector v = (Vector) names.get(name);
    String s = "";

    if (v == null) {
    s = null;
    }
    else {

    for (Enumeration e = v.elements(); e.hasMoreElements(); ) {
    s += (String) e.nextElement()+"\n";
    }
    }
    return s;
    }
    }
    unfortunately when i try to run the program i get errors that i cannot correct.i am new in java so it may be sth easy.....whats wrong with the code?

  2. #2
    Super Contributor
    Join Date
    Nov 2003
    Location
    Bangalore , India
    Posts
    4,429

    Re: what is wrong with the code?

    Please mention what errors you are getting. If possible please provide the complete source code so that some one here could atleast make it compilable for you!.

    Regards
    Gopal

Similar Threads

  1. Link errors when trying to Display bitmap
    By Bkc82 in forum Symbian Media (Closed)
    Replies: 1
    Last Post: 2006-01-16, 22:46
  2. Replies: 0
    Last Post: 2005-02-16, 14:20
  3. Progress bars: what's wrong with my code?
    By bobline in forum Symbian Tools & SDKs
    Replies: 2
    Last Post: 2003-05-29, 18:10
  4. Replies: 0
    Last Post: 2003-02-24, 04:00

Posting Permissions

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