帮忙编写一个文件传输的JAVA程序

来源:百度知道 编辑:UC知道 时间:2024/04/28 16:14:07
帮忙编写一个文件传输的JAVA程序
主要完成客户端与客户端之间的文件传输,服务器用来进行中转;
谢谢了!!
很急!!

如果文件太大不能一次全读入!!
JAVA里关于文件读写的有几十个类,不知道你想要如何实现,
以下是读文件的一个程序,如果有问题,发信息给我吧........

import java.io.*;
import java.nio.*;
import java.nio.channels.FileChannel;
public class javaTest {
public static void main(String[] args) {
String file1=System.getProperty("user.dir")+"/1.txt";//文件,自己修改

FileInputStream myFile = null;

try {
myFile = new FileInputStream(file1); //
} catch(FileNotFoundException e) {
e.printStackTrace(System.err);
System.exit(1);
}

FileChannel myChannel = myFile.getChannel();
//这里定义缓冲区大小,每次读入字节数
ByteBuffer mybuf = ByteBuffer.allocate(1024);

try {
while(myChannel.read(mybuf) != -1) {
byte[] mybytes = mybuf.array();//读入的文件转为字节数组
mybuf.clear();
/**
* 在这里进行比较
* 可以通过字节对比
* 也可以把字节转成字符串再对比
*
*/
}
myFile.close();

}catch(IOException e) {
e.p