BufferedReader cant read char

The reader object below is a BufferedReader and I initialized it like this
                                                               String fileName = "abc.txt"
               FileReader fr = new FileReader(fileName);
               BufferedReader reader = new BufferedReader(fr);The code below throws exception null... I dont know why .....
try{
               String s;
               int charValue;
                                                         System.out.println("******"); //PRINTS THIS
                                                            while ((charValue = reader.read()) != -1)// HERE IT THROWS                                                       {
                    System.out.println("--"); // DOESNT PRINT
                    boolean streamReady = reader.ready();
                    System.out.println(streamReady);
                    s=reader.readLine();
                    System.out.println(s);
               }//try
               catch(EOFException e){System.out.println("EOF excption");}
               catch(IOException e){System.out.println("IO exception");}
               catch(Exception e){System.out.println("Exception "+e.getMessage());}

Okay... e.printStackTrace worked.....
It gives
java.lang.NullPointerException
at LanguageRecognizer.getTransitionTable(LanguageRecognizer.java:59)
at LanguageRecognizer.promptUser(LanguageRecognizer.java:44)
at LanguageRecognizer.getFileName(LanguageRecognizer.java:23)
at Menu.show(Menu.java:42)
at RecognizerLauncher.main(RecognizerLauncher.java:6)
Its giving errors where I am calling other methods like for example:
I am calling from
public void promptUser()
{//blah blah
getTransitionTable(); // HERE
}

Similar Messages

  • Reading char from keyboard to stop threads?

    I want to kill all the threads an terminate my program execution when I enter some char, for example 'S'.
    BUT, I dont want the execution flow to wait in the sentence 'prompt.read()' until I enter some character.
    does somebody knows the solution?
    this is my program:
    import java.io.*;
    public class Finalizadora extends Thread {
         public static boolean ejecucion = true;
         public void run() {
              while (ejecucion) {
                   try {
                        sleep(1000);
                   } catch (Exception e) {
                        // Si falla el sleep lo simulamos
                        for (int i = 0; i < 1000 * 10; i++) {
                        } // fin del for
                   } // fin del try
                   try {
                        BufferedReader prompt = new BufferedReader(new InputStreamReader (System.in));
                        if (prompt.read() == 'S') {
                            ejecucion = false;
                        } // fin del if
                   } catch (Exception e) {
                        System.out.println("SOME FAILS!!");
                   //System.out.println("--------------------");
              } // fin del while
              System.out.println("ENDING...");          
         } // fin de parsear
    } // fin de Finalizadorathanks!

    Hello.I cant read chars from a file.I am trying to fing to character with Max Occurrence in a file but when I run it it stops abruptly.This is my code.Can you help me please.Thank you
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    * @author Dimitrios
    /*Assuming that the char with the max frequency in an standard English test is 'E' we can guess
    * that the char with the max frequency in the cipher text is E.This will
    * lead us to an approximation of the Key by shifting */
    import java.io.*;
    public class Frequency_Decprypt {
    public static int Occurrence(String str, char ch) {
    int occur=0;//the occurrence of char ch in the string
    for(int i=0;i<str.length();i++){
    if(str.charAt(i)==ch){
    occur++;
    return occur;
    public static char Frequency() throws IOException{
    BufferedReader in;
    FileReader fr;
    int key=0;
    char Max_FreqChar=' ';//the char with the max frequency
    int Max_Freq=0;// the max frequency of a char
    try{
    fr=new FileReader("Encrypted.txt");//the input file to read
    in=new BufferedReader(fr);
    //read a line from file
    String s=in.readLine();
    while(s!=null){
    for(int i=0;i<s.length();i++){
    if(Occurrence(s,s.charAt(i))>=Max_Freq){
    Max_Freq=Occurrence(s,s.charAt(i));
    Max_FreqChar=s.charAt(i);
    s=in.readLine();
    fr.close();
    //key=(int)('e'-Max_FreqChar);
    //key=Math.abs(key);
    } catch (FileNotFoundException e)
    { System.out.println("File not found");}
    return Max_FreqChar;
    }

  • How to user bufferedreader.read(char[] cbuf,int off,int len)

    how to user bufferedreader.read(char[] cbuf,int off,int len)?
    can you give me an sample code? i dont understand the use of offset here... thanks!

    The offset simply gives you the ability to read in data starting at some point in the buffer other than the first character.
    If, for example, you are reading from some stream that is being filled slower than you are reading, then you can write a read loop that will fill the buffer with successive reads - the first at character 0, then next offset past the end of the first set of data, etc.

  • How to read char from console

    Hi can any body help me..
    I want to read char from keybord. withought pressing ENTER.
    I am not sure how i can do it. I can't use
    BufferedReader br = new  BufferedReader(new InputStreamReader ( System.in )) ;
    char key ;
    key = (char )br.read() ;
    cuz i have to press ENTER every time to read char.
    Thanks in advance.

    try this,I' have found a part on Internet
    package exercises;
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    * questa � la classe d' esempio per leggere l'input dalla console*/
    public class Echo {
    public static void main(String args[]) throws Exception{
    // This is where the magic happens. We have a plain old InputStream
    // and we want to read lines of text from the console.
    // To read lines of text we need a BufferedReader but the BufferedReader
    // only takes Readers as parameters.
    // InputStreamReader adapts the API of Streams to the API of Readers;
    // receives a Stream and creates a Reader, perfect for our purposes.
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String input = "";
    while(true){
    System.out.print("ECHO< ");
    //As easy as that. Just readline, and receive a string with
    //the LF/CR stripped away.
    input = in.readLine();
    //Is a faster alternative to: if (input == null || input.equals(""))
    //The implementation of equals method inside String checks for
    // nulls before making any reference to the object.
    // Also the operator instance of returns false if the left-hand operand is null
    if ("".equals(input)){
    break;
    }else
    // Here you place your command pattern code.
    if ("ok".equals(input)){
    System.out.println("OK command received: do something �");
    //Output in uppercase
    System.out.println("ECHO> " + input.toUpperCase());
    System.out.println("ECHO> bye bye");
    //We exit without closing the Reader, since is standard input,
    // you shouldn't try to do it.
    // For all other streams remember to close before exit.
    }

  • Best way to read chars from InputStream

    Hope this is not a too newbie question.
    Suppose I have an unbuffered InputStream inputStream, what is the best way to read chars from it (in terms of performance)?
    Reader reader = new BufferedReader(new InputStreamReader(inputStream));
    reader.read()
    or
    Read reader = new InputStreamReader(new BufferedInputStream(inputStream))
    reader.read()
    Is there a difference between the two and if so, which one is better?
    thanks.

    If you are reading using a buffer of your own, then adding a buffer for binary data is a bad idea.
    However for text, using a BufferedInputStream could be better as it reduces calls to the OS.
    If it really matters, I suggest you do a simple performance test which runs for at least a few seconds to see what the difference is. (You should runt he test mroe than once)
    Edited by: Peter__Lawrey on 20-Feb-2009 21:37

  • Problem while using read(char[]) method of stream

    Hi I am trying to read different xml files, , hence i am using a buffered reader, and the read(char[]) method in the bufferereader.
    //rawContent - is the xml file content
          BufferedReader br = new BufferedReader(new InputStreamReader(rawContent,
              ENCODING_FORMAT));
          int ascii = 0;
          char ch[]= new char[200];
          while((ascii = br.read(ch)) != -1) {       
            rawContentBuffer.append(ch);
          }This is the error that i get when i execute the above piece of code. I have checked the files they have no white spaces after the xml contents.
    Please tell me how i can overcome this.
    2006-02-17 19:43:52,826 ERROR [com.test.web.taglib.LightTag] - Error in parsing the XHTMLContent is not allowed in trailing section.
    org.xml.sax.SAXParseException: Content is not allowed in trailing section.
          at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
          at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)
          at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
          at com.test.web.taglib.LightTag.renderField(LightTag.java:293)
          at com.test.web.taglib.LightTag.doStartTag(LightTag.java:128)

    Maybe it isn't. I don't know what 'rawContentBuffer' is, but you're assuming that 'ch' is always full when you call rawContentBuffer.append(ch). You need to call rawContentBuffer.append(ch,0,ascii) or some such form if there is one, or make some other arrangement for handling short reads.

  • Need official interpretation - java.io.Reader read(char[] cbuf) method

    Hello Everyone,
    I need Sun API's official interpretation on java.io.Reader read(char[] cbuf) method;
    Say, I provide this read method a char[] of size 8096, could the implementing class return even before reading into the whole buffer array? Say, the implementing class just reads 1024 chars and return 1024 as the method output, has the implementing class fulfilled its obligation?
    In my mind, the read method should attempt to read and fill the buffer array until of course i/o error occurs or end of stream is reached? See BufferedReader source for this type of implementation.
    Or could the read method just attempt to read into the buffer (with no obligation) and can return before completely filling the buffer?
    Sincere Regards.

    This is the situation: (and we are caught in between arbitrating on whom to ask to make the fix)
    Please note that I am not taking any names here, but remember these vendors are the biggest in their market.
    Vendor Db A has an API wherein it returns a stream and its length;
    Vendor B consumers this API via the java.io.Reader class as follows:
    char[] data = new char[(int) VendorAStream.length()];
    VendorAStream.read(data);
    Vendor B contends that per java.io.Reader API, it is responsibility of Vendor A to implement the read method correctly!!! (which is to read the data completely, not partially); Vendor B further contends that their code works fine with all the other Db vendors (except Vendor A); [Quite *tupid reasoning in my mind ;-) ]
    Vendor A says per java API, we can partially fill the buffer (they are specifically only reading 1024 chars from the stream)
    Initially, I thought, Vendor B must fix the code to handle partial reads. But no where it is mentioned clearly that Reader.read only attempts to read the chars and can return before filling the buffer.
    Dannyyates,
    (*My interpretation*) The reason it says "*maximum* number of characters to read" is for the situation when end of stream is reached before fully filling the buffer. In that case, the length of buffer and number of actually chars read wont match. This explanation covers for your observation (c)
    BIJ001, No problem in your explanation. I understand and I am merely pointing you to alternate interpretation of the API.
    Please comment. Thanks for your time to discuss this.
    Sincere Regards.

  • Reading char fail

    Hi everybody!
    Reading one char at a time from a file and saves where i last read.
    Next time when i start reading chars from where i last read in the file i
    only get char "?", and it reads chars like that the entire time. Any advice ?
    br.skip(last_read_in_file);
    while(readed_char != '\n'){
         if((int)(readed_char = (char) br.read()) != -1){
              if(readed_char != '\n'){
                   line_x = readed_line;
                   readed_line = new char[readed_line.length + 1];
                   for(int i=0;i<line_x.length;++i)
                        readed_line[i] = line_x;
                   readed_line[readed_line.length - 1] = readed_char;
         if(read_no_of_chars >= size_of_file){
              readed_char = '\n';
         System.out.println("readed_char: " + readed_char);
         ++read_no_of_chars;

    The FIRST time i read the file there is no problem when i'm reading chars.
    The SECOND time it returns "?" or 65535. There has to be something with skip(long n) ?
    fx = new File("C:\\Temp\\Log.txt");
    // Get the size of the file.
    noOfChars = (int)fx.length();
    // If last_read_in_file is smaller then the size of
    // of the file, it means that new errors
    // has been added to the file. Otherwise,
    // jump out of this error-detecting function.
    if (last_read_in_file >= noOfChars) {
         logger.info(fx.getName() + " - done, no changes in file.");
         return;
    // Initiate file-readers.
    in = new FileInputStream(fx);
    fr = new InputStreamReader(in, charset);
    br = new BufferedReader(fr);
    // Jump to the latest read line.
    read_no_of_chars = last_read_in_file;
    try {
         in.skip(last_read_in_file);
         fr.skip(last_read_in_file);
         br.skip(last_read_in_file);
    } catch (IOException e1) {
         e1.printStackTrace();
    // Reading a line from the file which, perhaps,
    // contains errors. In this while-loop a char is
    // being read one at the time and is being added
    // in a char-array. Thanks to the CharSet, when
    // we're at the end of the file, it won't
    // return the value -1. So instead, we have a
    // word-counter that we compare with 'noOfChars'
    // to see if we're at the end of the file.
    while(readed_char != '\n'){
         if((int)(readed_char = (char) br.read()) != -1){
              if(readed_char != '\n'){
                   line_x = readed_line;
                   readed_line = new char[readed_line.length + 1];
                   for(int i=0;i<line_x.length;++i)
                        readed_line[i] = line_x;
                   readed_line[readed_line.length - 1] = readed_char;
         if(read_no_of_chars >= noOfChars){
              readed_char = '\n';
         System.out.println("readed_char: " + readed_char + " (" + (int)readed_char + ")");
         ++read_no_of_chars;
    temp = new String(readed_line);

  • I got an itunes card cant read letters apple sent me a form in the email was no form just a link that brought me to support page i wasted 25$ for this card i just want anotheer code

    i got an itunes card and i cant read the letter i wasted 25$ for nothing since i cant use it i called customer support they said they sent me a form in my email to fill out there was no form in my email to fill out just a bunch of links that brought me to the main screen in the support page ive went all throughout the support page and cant seem to find this form or something that will help me all i want is a new code so i can use this card can you please just send me a new 25$ code

    See:
    iTunes Store: Invalid, inactive, or illegible codes

  • Hi im having huge problems trying to install flash for my mac 10.5 imac, iv gone through the internet and tried all of the solutions, everytime i try to install flash it says cant read the download file, or it just wont install, anybody plz help!

    hi im having huge problems trying to install flash for my mac 10.5 imac, iv gone through the internet and tried all of the solutions, everytime i try to install flash it says cant read the download file, or it just wont install, anybody plz help!
    iv unistalled flash, iv checked plug ins it just wont work,

    It would have been a great help to know precisely what Mac you have, so some of the following may not apply:
    You can check here:  http://www.adobe.com/products/flash/about/  to see which version you should install for your Mac and OS. Note that version 10,1,102,64 is the last version available to PPC Mac users*. The latest version,10.3.183.23 or later, is for Intel Macs only running Tiger or Leopard, as Adobe no longer support the PPC platform. Version 11.4.402.265 or later is for Snow Leopard onwards.
    (If you are running Mavericks: After years of fighting malware and exploits facilitated through Adobe's Flash Player, the company is taking advantage of Apple's new App Sandbox feature to restrict malicious code from running outside of Safari in OS X Mavericks.)
    * Unhelpfully, if you want the last version for PPC (G4 or G5) Macs, you need to go here:  http://kb2.adobe.com/cps/142/tn_14266.html  and scroll down to 'Archived Versions/Older Archives'. Flash Player 10.1.102.64 is the one you download. More information here:  http://kb2.adobe.com/cps/838/cpsid_83808.html
    You should first uninstall any previous version of Flash Player, using the uninstaller from here (make sure you use the correct one!):
    http://kb2.adobe.com/cps/909/cpsid_90906.html
    and also that you follow the instructions closely, such as closing ALL applications (including Safari) first before installing. You must also carry out a permission repair after installing anything from Adobe.
    After installing, reboot your Mac and relaunch Safari, then in Safari Preferences/Security enable ‘Allow Plugins’. If you are running 10.6.8 or later:
    When you have installed the latest version of Flash, relaunch Safari and test.
    If you're getting a "blocked plug-in" error, then in System Preferences… ▹ Flash Player ▹ Advanced
    click Check Now. Quit and relaunch your browser.
    You can also try these illustrated instructions from C F McBlob to perform a full "clean install", which will resolve the "Blocked Plug-in" message when trying to update via the GUI updater from Adobe.
    Use the FULL installer for 12.0.0.44:  Flash Player 12 (Mac OS X)
    And the instructons are here: Snow Leopard Clean Install.pdf
    (If you are running a PPC Mac with Flash Player 10.1.102.64 and are having problems with watching videos on FaceBook or other sites, try the following solution which fools the site into thinking that you are running the version 11.5.502.55:)
    Download this http://scriptogr.am/nordkril/post/adobe-flash-11.5-for-powerpc to your desktop, unzip it, and replace the current Flash Player plug-in which is in your main/Library/Internet Plug-Ins folder, (not the user Library). Save the old one just in case this one doesn't work.

  • External hard drive seagate 3.0 cant read and not showing in disk management.

    Why my external hard drive seagate 3.0 cant read and not showing in disk management, while 2.0 can read. please help me to solve it. BIG THANK YOU.. 

    Hi,
    Yes, like Vegan said, you should check if your Seagate hard drive if it could available in USB 3.0 port. This is hardware related.
    Karen Hu
    TechNet Community Support

  • Hello, I have an iPad Mini WiFi Cellular white 16Gb and I puted my sim inside it but, I cant read the text message that I recieve in the Sim. What can i do? And I can't put the sim in a cellphone coz it doesn't recognize it. Please help me! Thank you.

    Hello, I have an iPad Mini WiFi Cellular white 16Gb and I puted my sim inside it but, I cant read the text message that I recieve in the Sim. What can i do? And I can't put the sim in a cellphone coz it doesn't recognize it. Please help me! Thank you.

    iPads do not do SMS.

  • I am running windows 8 and have lightroom 5.5 and i have a error that says cant read from previous cache?  help

    I am running windows 8 and have lightroom 5.5 and i have a error that says cant read from previous cache?  help

    Using Windows Explorer, navigate to the folder that contains your catalog it's probably located in Pictures\Lightroom. In that folder you will find another folder with the extension .lrdata. You need to delete that folder and its contents, then start Lightroom again. And new previews folder will be created automatically, and you should be able to start using Lightroom normally.

  • InputStreamRead read(char[] cbuf, int offset, int length) method hangs

    This method hangs for the following values
    read(xchar, 0, 1)
    Does not throw any exception.
    The inputstream does have data in it.
    the characterset is cp037.

    So the problem is probably in your implementation of InputStream. Do you implement the available() method? What will your class do if you attempt to read more bytes than there are? (say, call read(chars, 0, 1000000))
    The InputStreamReader keeps an internal buffer (of 1024 bytes?) which it uses for decoding the bytesto characters..if your stream blocks when InputStreamReader is filling its buffer you'd get this sort of behaviour.

  • I cant read PDF files on my blackberry curve 8520.

    I cant read PDF files on my blackberry curve 8520. Its not working, please help.

    You will need PDF file reader application in you smartphone to read PDF files. But if you receive PDF files as email attachments then they'll open in your phone.
    tanzim                                                                                  
    If your query is resolved then please click on “Accept as Solution”
    Click on the LIKE on the bottom right if the post deserves credit

Maybe you are looking for