java利用Socket网络传递文件
服务器端:
package com.huahua;
import java.io.BufferedOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
public class ServerThread extends Thread {
private Socket socket;
public ServerThread(Socket socket) {
super();
this.socket = socket;
}
public void run(){
try {
while(true){
DataInputStream in = new DataInputStream(socket.getInputStream());
//接收保存的路径
String path = "e:\\" + in.readUTF();
//接收的文件长度
long length = in.readLong();
//保存文件
DataOutputStream out = new DataOutputStream(new BufferedOutputStream(
new FileOutputStream(path)));
byte[] buf = new byte[1024];
int len = 0;
while((len=in.read(buf))!=-1){
out.write(buf,0,buf.length);
}
out.flush();
out.close();
in.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args){
try {
ServerSocket serverSocket = new ServerSocket(9999);
while(true){
new ServerThread(serverSocket.accept()).start();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
客户端:
package com.huahua;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.Socket;
public class Client{
public static void main(String[] args){
FileInputStream fin = null;
DataOutputStream out = null;
try {
Socket socket = new Socket("127.0.0.1",9999);
File file = new File("f:\\张惠妹 - 彩虹.wma");
out = new DataOutputStream(socket.getOutputStream());
//传送文件名称
out.writeUTF(file.getName());
out.flush();
//传送文件长度
out.writeLong(file.length());
out.flush();
//传送文件
fin = new FileIn
相关文档:
package test;
/**
*
* @author openpk
*/
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Semaphore;
public class Main {
public static void main(String[] args) {
// 线程池
ExecutorService exec = Executors ......
3.1 跨平台三维图形开发工具包Java 3D
官方主页:https://java3d.dev.java.net/
Java 3D严格遵循“建模-绘制”泛型。场景图(scene graph)的 抽象模型被用来组织和维护虚拟场景中的可是对象及其行为。场景图包含了虚拟图形世界的全部信息,Java 3D绘 制引擎会对场景图进行自动绘制。
Java 3D is a scene g ......
在Firefox 3.6中,当焦点在flash或者java applet对象上时,会出现一个环绕对象的虚线框,当将flash与java applet对象的大小设成100%时,点击对象后页面会出现滚动条,影响显示效果,解决的方法是使用如下的css定义:
:focus {
outline: 0;
}
这样在各个不同的浏览器中显示的效果都能保持一致。 ......
KeywordFilter.java:
import java.io.InputStream;
import java.util.Enumeration;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class KeywordFilter
{
private static Pattern pattern = null;
private static KeywordFilter filter = new KeywordF ......
public class Multiplication
{
public static void main(String[] args)
{
// TODO Auto-generated method stub
for(int i = 1; i < 10; i+ ......