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);

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;
    }

  • Help!!! T61 Blue Screen--unmountable boot volume-- error code 0000: Read verification failed

    My computer is T61 (8891CT), but Blue Screen came out and reported--unmountable boot volume.  I ran the diagnostic program and got the error code 0000: Read verification failed. I can’t run anything now including the restore and rescue.  Has the hard drive died?
    If the hard drive has died, I have to change the hard drive, but how to transfer the system (I don’t have any CD) and think vantage software? Thank you very much for you help.

    Hi equalefk,
    Yes, definitely sounds like it's time to replace the HDD.
    Hope it helps.
    Maliha (I don't work for lenovo)
    ThinkPads:- T400[Win 7], T60[Win 7], IBM 240[Win XP]
    IdeaPad: U350
    Apple:- Macbook Air [Snow Leopard]
    Did someone help you today? Compliment them with a Kudos!
    Was your question answered today? Mark it as an Accepted Solution! 
      Lenovo Deutsche Community     Lenovo Comunidad en Español 
    Visit my YouTube Channel

  • I installed itunes and quick time  but when I try to open itunes I get a message that reads "quicktime failed to initialize (error -2096)"

    I installed itunes and quick time  but when I try to open itunes I get a message that reads "quicktime failed to initialize (error -2096).  I have removed both itunes and quicktime from my computer and re-installed them and I still get the same message.  What do I do to get itunes to work?

    That one is often a compatibility mode problem. Try the following document, only be sure that none of the boxes in the compatibility mode tab are checked (not just the compatibility mode box itself):
    iTunes for Windows: How to turn off Compatibility Mode

  • 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.

  • 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.
    }

  • 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.

  • 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

  • T430 2342CTO - SanDisk 16GB mSATA Target Read Test Fail

    Hi all, my Lenovo Solution Center (LSC) told me that my mSATA had a targetd read test fail.  I ran the test myself and it had the same issue.  Read some threads and tried the LSC test but only tested the SSD, and it passed all tests when ran this way.
    Went to the IBM Electronic Service Call website and entered the details and they sent me an empty box to ship my laptop back for repair.  This seems overkill as I'm sure I could just pop in a new mSATA if that really was the problem, I don't want to give up my PC.
    My T430 seems to run fine.  Wondering  if this is a software problem with LSC? Here is my error code:
    LENOVO HARDWARE SCAN ERROR: RESULT CODE: WHD01V002-UI8VYJ DATE RUN: 1/26/2013 - 14:52 DEVICE: SANDISK-SANDISKSSDU10016GB-123659310730
    (don't get this error when I test the SSD by itself, only if SSD is tested right after the primary HD)
    Is it worth sending back to Lenovo? Or does LSC have a glitch?
    Thanks for any input
    Graeme
    Solved!
    Go to Solution.

    I'd like to hear the answer to this as I'm on my second drive in 2 months of ownership. No symptoms other than that it failed this test.
    Replacing the drives create a lot of work after because you have to reload all your programs, files and configure everything as you would for a new computer. They seen to want to keep throwing parts at this fix on mine.

  • READ DATASET  fails!

    Hi,
    data: dsn(95) value '/usr/sap/U6B/D85/work/jana10'.    "dsn data is filled by another program
    DATA: BEGIN OF STR,
             STLNR LIKE STZU-STLNR,
             CNTRL,
          END OF STR.        " this is a pure character type structure
    OPEN DATASET DSN IN TEXT MODE FOR OUTPUT ENCODING UTF-8.
    READ DATASET DSN INTO STR.
    Read always fails in here with subrc = 4.
    Any idea what i have to change to get this working?
    Thanks,
    Ashvini.

    Hello Ashvini
    Combine ... FOR OUTPUT... with ...TRANSFER...    and
    ... FOR INPUT...  with  ...READ DATASET...
    Regards
      Uwe

  • Adobe Reader installer fails

    Adobe Reader installer fails to install.
    Task Manager shows it's running, but nothing happens.
    Can't run it again because error message says a copy is already running.
    Help!

    You can try using the full offline Reader installer from
    http://get.adobe.com/reader/enterprise/

  • Adobe Reader 10 failed to  install. Upgrade hung up at "installing Features" & locked up system.

    Adobe Reader 10 failed to  install. Upgrade hung up at "installing Features" & locked up system.  Tried second time and got "process interrupted" error.  Trch support NOT available, chat not available, nothing here seems to work.

    When everything else fails, you may want to try the following:
    Run this fix from Microsoft: http://support.microsoft.com/mats/Program_Install_and_Uninstall
    Uninstall all traces of any versions of Reader using Add/Remove Programs
    If you want to reinstall Reader, download it from http://get.adobe.com/reader/enterprise/

  • I need help installing Acrobat Reader - messaged failed to connect to a DDE Server. Can't access documents

    I need help installing Acrobat Reader - messaged failed to connect to a DDE Server. Can't access documents

    Please see if "acrobat failed to connect to dde server" when openning Adobe Acrobat XI PRo helps.

  • Reader X fails install in Windows XP SPK3

    Why does Adobe Reader X fail during installation in Windows XP spk3? I
    t gets about 2/3 through and then exits with an error.
    I have tried uninstalling and re-installing.  I have tried a registry cleanner.
    What do I need to do to have the installation work?
    I also tried downloading it from a different URL.

    I found the solution to my problem with installing Adobe Reader X in Windows XP SPK3.
    I ran a tool from Microsoft to do a "clean" uninstall of Reader X.  Before I ran this tool, it appeared as though Reader was removed, but upon going back into add/remove programs, there it was again.  This tool "fixed " the uninstall problem and uninstalled Reader.  Now I installed Reader X with NO problems.
    http://support.microsoft.com/mats/Program_Install_and_Uninstall

  • Datawarehouse Admin Console : Reading column failed

    While importing column from Database (MSSQL) into Datawarehouse Admin Console i am getting below error.
    Reading Columns failed
    com.siebel.analytics.etl.schema.reader.SchemaReaderException: Error while initializing the list of tables.
    Help me to resolve the issue.
    Thanks
    Lakshmi

    Best try another forum for the BIApps DAC questions
    Cheers
    David

Maybe you are looking for