我只能大概的说明一下,不能帮你些具体的代码。你可以用FileReader和OutputStreamWriter两个类结合着用,FileReader的readLine方法读取字符到一个字符串变量后,马上用OutputStreamWriter的flush方法发送这个字符串。如此往复的循环直到文件读完为止。对于二进制的文件就只用使用FileInputStream和OutputStream两个类。
解决方案 »
- 有人用过zeroMQ吗?一直提示C:\Program Files\Java\jre6\bin\jzmq.dll: Can't find dependent li
- Entitymanager的问题,急!!!!
- java和C中如何把IP转换成网络字节顺序相互传输?
- 谁知道swing里如果打印表单转换成excel文档格式在进行打印如何实现啊?
- 请问五子棋禁手算法的思路?
- 跪求大神帮忙写一个java小程序,所有的分都送上了
- Java创建字符串常量内存分析
- 一个简单的问题请高手回答
- MS Access的纯java的驱动那里下载?
- 一个类中使用另一个类的实例变量作为成员时,提示类找不到,这是怎么回事?
- 用JavaScrpt实现文件夹轻松加密?帮忙看看这个
- 怎样获取系统的前进,后退的箭头图标
File file=new File("c://88.txt");
File outfile=new File("d://88.txt");
FileInputStream in=new FileInputStream(file);
FileOutputStream out=new FileOutputStream(outfile);
int i;byte[] d=new byte[];
while((i=in.read(d))!=-1){
out.write(d);
}
out.close();
in.close();
File file=new File("c://88.txt");
File outfile=new File("d://88.txt");
FileInputStream in=new FileInputStream(file);
FileOutputStream out=new FileOutputStream(outfile);
int i;byte[] d=new byte[];
while((i=in.read(d))!=-1){
out.write(d,0,i);
}
out.close();
in.close();
//服务器端:
//: RockServer.java
import java.net.*;
import java.io.*;public class RockServer {
public static final int PORT = 8080;
public static void main(String[] args) throws IOException {
ServerSocket srvSocket = new ServerSocket(PORT);
System.out.println("Start " + srvSocket);
try {
Socket socket = srvSocket.accept();
try {
System.out.println("Connection accepted:" + socket);
BufferedReader in = new BufferedReader(
new InputStreamReader(
new FileInputStream("RockClient.java")));
PrintWriter out =new PrintWriter(
new BufferedWriter(
new OutputStreamWriter(socket.getOutputStream())), true);
while(true) {
String str = in.readLine();
if(str==null)
break;
System.out.println("Sending to Client: " + str);
out.println(str);
}
} finally {
System.out.println("Closing...");
socket.close();
}
} finally {
srvSocket.close();
}
}
}//客户端:
////: RockClient.java
import java.net.*;
import java.io.*;public class RockClient {
public static void main(String[] args) throws IOException {
int port = RockServer.PORT;
InetAddress addr =InetAddress.getByName(null);
System.out.println("addr= " + addr);
Socket socket =new Socket(addr, port);
try {
System.out.println("socket= " + socket);
BufferedReader in = new BufferedReader(
new InputStreamReader(socket.getInputStream()));
PrintWriter out = new PrintWriter(
new BufferedWriter(
new OutputStreamWriter(
new FileOutputStream("client.txt"))), true);
while(true) {
String str = in.readLine();
if(str==null)
break;
System.out.println("Receiving from Server: " + str);
out.println(str);
}
} finally {
socket.close();
}
}
}