Results 1 to 4 of 4

Thread: Print problem

  1. #1
    PROPA is offline Member
    Join Date
    Nov 2011
    Posts
    6
    Rep Power
    0

    Default Print problem

    Ok so here is my code and the file it reads from?
    can anyone tell me what the problem is here. cheers:

    XML Code:
    public void readText(String file)throws Exception{
            
            fr = new FileReader(file);
            
            int ch;
            
            while(((ch = fr.read()) != -1) && ((ch = fr.read()) != ' '|| ((ch = fr.read()) != '\n'))){
                
                System.out.print(Character.toChars(Character.toLowerCase(ch)));
                
    //             switch(ch){
    //                 case 'a'|'b'|'c'|'d'|'e'|'f'|'g'|'h'|'i'|'j'|'k'|'l'|'m'|'n'|'o'|'p'|'q'|'r'|'s'|'t'|'u'|'v'|'w'|'x'|'y'|'z':  
    //                     char c = (char)ch;
    //                     token.identifier.add(Character.toString(c));
    //                     ch = fr.read();
    //                     break;
    //                 case '0'|'1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9':
    //                     char n = (char)ch;
    //                     token.identifier.add(Character.toString(n));
    //                     break;
    //             }
                
            }
        }
    the test file:

    {
    define a = 0999;
    integer integera=-12345,vara,b2b,const1, two2, three3;
    a+b-c*d/e=end * ** * ;
    abc+123def()
    ==
    print(print1)}

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,956
    Rep Power
    8

    Default Re: Print problem

    How about you tell us what the problem is? What do you expect to happen? What happens instead?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    PROPA is offline Member
    Join Date
    Nov 2011
    Posts
    6
    Rep Power
    0

    Default Re: Print problem

    I'm getting so t'd off I forgot to say what the problem is. HA!

    when I print, it only displays a few of the ltters even though it should keep all of the characters except for the whitespaces and tabs.
    I've commented out the switch case statement but there is a problem here too. I need it to store the first character is picks up if this character is a letter, it should then continue reading and if the next character is a letter or digit, it should store it along with the first character and return as an identifier.

    I hope i have explained the problem well.

  4. #4
    Shoss's Avatar
    Shoss is offline Member
    Join Date
    Feb 2011
    Posts
    94
    Rep Power
    0

    Default Re: Print problem

    Every time you call fr.read(), it pulls another character out of the stream. That's why it is only printing every other character - it pulls one out to do the "!= -1" comparison and another one or two for the "!= ' '" and "!= '\n'" comparisons before it finally prints out to the console. You need to call fr.read() only once per each run through the loop, store it in a temporary variable, and run your checks against that.

Similar Threads

  1. Need help with print
    By lala in forum New To Java
    Replies: 0
    Last Post: 11-25-2010, 05:24 PM
  2. ireport problem on print
    By urtley in forum Advanced Java
    Replies: 0
    Last Post: 08-05-2009, 11:12 PM
  3. problem with PrintService in javax.print package
    By sandeepsai17 in forum New To Java
    Replies: 0
    Last Post: 07-13-2009, 10:27 AM
  4. Print the text file and print preview them
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-22-2008, 11:04 PM
  5. Print A Pdf
    By Jack in forum Advanced Java
    Replies: 2
    Last Post: 07-02-2007, 05:40 AM

Posting Permissions

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