当前位置: 技术问答>java相关
你给我答案,我给你分数。
来源: 互联网 发布时间:2015-01-11
本文导语: 程序如下: //Server端 import java.io.*; import java.net.*; import java.util.*; public class IOtestSvr { public static void main(String[] args) { boolean on = true; try { ServerSocket svrSocket = new ServerSocket(8000); while (on) { System.out.p...
程序如下:
//Server端
import java.io.*;
import java.net.*;
import java.util.*;
public class IOtestSvr {
public static void main(String[] args)
{
boolean on = true;
try
{ ServerSocket svrSocket = new ServerSocket(8000);
while (on) {
System.out.println("begin");
Socket socket = svrSocket.accept();
DataInputStream in = new DataInputStream(socket.getInputStream());
byte[] bTest = new byte[1024];
int i = in.read(bTest);
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
//Client
import java.io.*;
import java.net.*;
import java.util.*;
public class IOtestCli {
public static void main(String[] args)
{
System.out.println("Hello World!");
try {
Socket socket = new Socket("127.0.0.1",8000);]
DataOutputStream out = new DataOutputStream(socket.getOutputStream());
out.writeChars("String 1" + 'n'+'r');
out.writeChars("一个测试");
out.writeChar('a');
out.writeChars("Sting 2" + 'r');
out.flush();
out.close();
socket.close();
}
catch (Exception e) {
System.out.println("Err");
e.printStackTrace();
}
}
}
试问i=?
(我这的结果是i=1,哪位高人能解释下么?谢谢谢谢谢谢。)
//Server端
import java.io.*;
import java.net.*;
import java.util.*;
public class IOtestSvr {
public static void main(String[] args)
{
boolean on = true;
try
{ ServerSocket svrSocket = new ServerSocket(8000);
while (on) {
System.out.println("begin");
Socket socket = svrSocket.accept();
DataInputStream in = new DataInputStream(socket.getInputStream());
byte[] bTest = new byte[1024];
int i = in.read(bTest);
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
//Client
import java.io.*;
import java.net.*;
import java.util.*;
public class IOtestCli {
public static void main(String[] args)
{
System.out.println("Hello World!");
try {
Socket socket = new Socket("127.0.0.1",8000);]
DataOutputStream out = new DataOutputStream(socket.getOutputStream());
out.writeChars("String 1" + 'n'+'r');
out.writeChars("一个测试");
out.writeChar('a');
out.writeChars("Sting 2" + 'r');
out.flush();
out.close();
socket.close();
}
catch (Exception e) {
System.out.println("Err");
e.printStackTrace();
}
}
}
试问i=?
(我这的结果是i=1,哪位高人能解释下么?谢谢谢谢谢谢。)
|
你为什么一定要用DIS和DIO呢?
Data input streams and data output streams represent Unicode strings in a format that is a slight modification of UTF-8.
直接用InputStream和OutputStream不更好?
InputStream in = socket.getInputStream();
OutputStream out = socket.getOutputStream();
...
Data input streams and data output streams represent Unicode strings in a format that is a slight modification of UTF-8.
直接用InputStream和OutputStream不更好?
InputStream in = socket.getInputStream();
OutputStream out = socket.getOutputStream();
...
|
这是JDK的问题,更新到jdk1.3.1就好了