当前位置: 技术问答>java相关
如何以字节流读取一个文件,以readline()读出?大哥快帮忙!
来源: 互联网 发布时间:2015-01-25
本文导语: | import java.io.*; import java.net.*; import java.util.*; private Socket socket; public void SendFileToServer(String strSourceFileName) { //strSourceFileName需要发送的文件名(带路径) try{ FileInputStream fis = new FileInputStrea...
|
import java.io.*;
import java.net.*;
import java.util.*;
private Socket socket;
public void SendFileToServer(String strSourceFileName)
{
//strSourceFileName需要发送的文件名(带路径)
try{
FileInputStream fis = new FileInputStream(strSourceFileName);
BufferedInputStream bis = new BufferedInputStream(fis);
DataInputStream in2 = new DataInputStream(bis);
BufferedOutputStream out2 = new BufferedOutputStream(socket.getOutputStream());
byte[] b = new byte[1024];
int c;
while ((c=in2.read(b))!=-1)
{
out2.write(b,0,c);
out2.flush();
}
in2.close();
out2.close();
}catch(IOException e){
}
}
public void ReceiveFileFromServer(String strAimFileName)
{
try{
DataInputStream inFile = new DataInputStream(new BufferedInputStream(inStream));
BufferedInputStream in = new BufferedInputStream(socket.getInputStream());
BufferedOutputStream bfs = new BufferedOutputStream(new FileOutputStream("d:/test/"+strAimFileName)); //收到文件后,所放置的位置
byte[] d = new byte[1024];
int x;
x=in.read(d);
int i=x;
while (i filepointer)
{
filepointer = fff.getFilePointer();
sss = fff.readLine();
System.out.println("filepointer : "+filepointer+" "+sss);
}
fff.close();
}
catch(FileNotFoundException dd)
{
System.out.println("no file");
}
catch(IOException s)
{
System.out.println("read file error");
}
}
}
import java.net.*;
import java.util.*;
private Socket socket;
public void SendFileToServer(String strSourceFileName)
{
//strSourceFileName需要发送的文件名(带路径)
try{
FileInputStream fis = new FileInputStream(strSourceFileName);
BufferedInputStream bis = new BufferedInputStream(fis);
DataInputStream in2 = new DataInputStream(bis);
BufferedOutputStream out2 = new BufferedOutputStream(socket.getOutputStream());
byte[] b = new byte[1024];
int c;
while ((c=in2.read(b))!=-1)
{
out2.write(b,0,c);
out2.flush();
}
in2.close();
out2.close();
}catch(IOException e){
}
}
public void ReceiveFileFromServer(String strAimFileName)
{
try{
DataInputStream inFile = new DataInputStream(new BufferedInputStream(inStream));
BufferedInputStream in = new BufferedInputStream(socket.getInputStream());
BufferedOutputStream bfs = new BufferedOutputStream(new FileOutputStream("d:/test/"+strAimFileName)); //收到文件后,所放置的位置
byte[] d = new byte[1024];
int x;
x=in.read(d);
int i=x;
while (i filepointer)
{
filepointer = fff.getFilePointer();
sss = fff.readLine();
System.out.println("filepointer : "+filepointer+" "+sss);
}
fff.close();
}
catch(FileNotFoundException dd)
{
System.out.println("no file");
}
catch(IOException s)
{
System.out.println("read file error");
}
}
}
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。