Transmitting Integers in Java Socket Programming

Status
You're currently viewing only pholus's posts. Click here to go back to viewing the entire thread.
Not open for further replies.
This worked for me

code:<HR>
Code:
import java.io.*;<P>public class test {
	
	public static void main(String args[]) {
		try {
			byte[] b = new byte[100];
			System.out.print("Enter Integer: ");
			int len = System.in.read(b); 
			String str = new String(b, 0, (len - 2));
			int output = new Integer(str).intValue();
			System.out.println(output);
		} catch (IOException e ) {
			System.exit(-1);
		}	
	}<P>}

Hope this helps =)
P.S. Don't know why the length keeps returning 2 plus the length of the array.
 
Status
You're currently viewing only pholus's posts. Click here to go back to viewing the entire thread.
Not open for further replies.