Java socket 入门编程实例
这是一个C/S之间通信的例子,在JDK1.4下测试通过.
//服务器端源程序tcpserver.java
import java.io.*;
import java.net.*;
public class tcpserver
{
public static void main(String[] args) throws IOException
{
ServerSocket svrsoc=null;
Socket soc=null;
DataInputStream in=null;
PrintStream out=null;
InetAddress clientIP=null;
String str=null;
try
{
svrsoc=new ServerSocket(8000);
System.out.println("Server start....");
soc=svrsoc.accept();
in=new DataInputStream(soc.getInputStream());
out=new PrintStream(soc.getOutputStream());
clientIP=soc.getInetAddress();
System.out.println("Client's IP address:"+clientIP);
out.println("welcome.....");
str=in.readLine();
while (!str.equals("quit"))
{
 
相关文档:
构造方法:
String()
初始化一个新创建的 String 对象,它表示一个空字符序列。
String(byte[] bytes)
构造一个新的 String,方法是使用平台的默认字符集解码字节的指定数组。
String(byte ......
在这里介绍两种方法生成jar,第一种是用Eclpise的Export功能。在要打包的项目上击右键,选择Export,在窗口中选择Java里的JAR file。Next后的窗口中已经自动选好了要打包的项目,用户可以点击加号查看项目里被打包的内容。在下面的JAR file里设置你打包生成jar文件的输出目录,下一步在出现的窗口中选择Use existin ......
java调用外部程序 必杀 路径空格没有问题
Runtime rt = Runtime.getRuntime();
srcFile.getName();
try {
String cmd[]={"cmd","/c",srcFile.getAbsolutePath()};
rt.exec(cmd);
} catch (IOException e1) {
// TODO Auto-genera ......
1、类型模板 Class:
物以类聚:
我们可以用class Person{ } class Animal{ }来描述一类人或一类动物;
那么再想一下,我们是不是可以用class Class{ } 来抽象描述类呢?
答案时可以的,这就是jdk中的 Class 类(类� ......
以下代码能否编译通过,如果不能,请说明理由,如果能,请说明结果。
public class a {
{
System.out.println("AAA");
}
a() {
System.out.println("BBB");
}
{
System.out.println("CCC");
}
class aa extends a {
{
new a();
System.out.prin ......