Need Help Again Reading Data From Inputstream

Yesterday i posted a question about a problem i had concerning inputstream reading and i was helped.

I find myself in similar situation but this time i know that I am doing the right thing but yet it is not working for me.

I am reading from an inputstream but i get different value. No matter how i change the data i send i get the same string ("toForklift-42") as the value. At first i prefix the value i send with "toForklift-" but i have changed that string to different strings yet i get the same string in the bracket. i Even changed the number 42 to a different number but yet when i run the program, i get the same string in the console. Below is what am sending : as

Two classes for sending and receiving.

Am using the leJOS NXJ NXTConnector to make the connection and open the streams.

// sender class

class PanButton implements Runnable {

    DataInputStream dis;
    DataOutputStream dos;
    TouchSensor touch = new TouchSensor(SensorPort.S4);

    PanicButtonCrossing(DataInputStream is, DataOutputStream os) {
    dos = os;
    dis = is;

    public void run() {

        while (!touch.isPressed())  {}

            // If you get a message: KILL EVERYTHING    

            try { // send 42
                int value = 42;

                dos.writeChars("ggggggggg" + 455 + "\n"); 
                Sound.systemSound(true, 3);
            } catch (IOException ioe) {
                LCD.drawString("Write Exception", 0, 0);



// Reader classs

public class InputReaderCrossing  implements Runnable{

      private DataInputStream dataIn;
      private DataOutputStream dataOut;

public InputReaderCrossing(DataInputStream dataIn, DataOutputStream dataOut) {
            this.dataIn = dataIn;
            this.dataOut = dataOut;
            this.sensor = sensor;
            this.readLock = new Object();


public void run(){


String dataFromCrossing1 = readLineFromCrossing();
System.out.println("CROSSING VALUE: " + dataFromCrossing1  + "  :VALUEEEEE");


private String readLineFromCrossing() throws IOException{ 
              StringBuffer sb = new StringBuffer(); 

                 while(true) { 
                    char c = this.dataIn.readChar(); 
                    if (c == '\n') break; 
                 return sb.toString(); 


I need your help please. i have spent 6 hours but can't find the the reason. I don't understand no matter what i send i get "toForklift-42".

At first i tried to send the 42 with the writeInt() methods but then on the reader class side i use readInt() but i get somethings like:


So i changed to the string to find out why and lo and behold i get that string no matter what i send. it is like that string is fixed in the input stream and nothing is sent. I don't know what is happening.

Need help


This is a very confusing question. We don't really know which process is writing which data, and how it's being transmitted, and which process is picking it up. There's some relevant code to see here, but I didn't see enough to tell the story. How did dataFromCrossing1 get its value?

I think it would do good to organize your problem in such a way that you can ask an outsider a question about it. Possibly in the process of doing so you could stumble on the solution yourself.

In principle, if you are changing string constants in your program yet you continue to see the same output, then what's happening is that

  • The original program is still running; or
  • all versions since the original have had errors, so the class files you once compiled successfully are running again and again; or
  • you're not really running the program you think you're running.

Need Your Help

postback on click for type ahead drop down

c# drop-down-menu postback typeahead

I have a type a head drop down list that I created. Clearly I had to turn the AutoPostBack to false because otherwise it would post back as the user was typing. But I want to poast back when use ha...

Verifying mime type of pdf files on upload in PHP

php pdf file-upload

I am working on a project that requires file uploads. I want to make sure it's secure and that only PDF files are being uploaded. I am already checking file extension but i want to make sure the file