Article View: borland.public.jbuilder.java.language
Article #15072Re: Looking for source for transfering binary files via socket
From: Mica Cooper
Date: Thu, 15 Jul 1999 00:00
Date: Thu, 15 Jul 1999 00:00
49 lines
2077 bytes
2077 bytes
Try this, it worked for me on char files...change it to datastreams.
// Set the client socket up to send
int small_buf_size = 1024;
try{
OutputStream os = clientsocket.getOutputStream();
BufferedOutputStream bos = new BufferedOutputStream(os,
small_buf_size);
// read client file
try{
File f = new File(filepath);
FileInputStream is = new FileInputStream(f);
BufferedInputStream bis = new BufferedInputStream(is);
byte[] buf = new byte[small_buf_size];
int count;
while (( count = bis.read(buf))>0){
bos.write(buf,0,count);
}
bis.close();
}
catch(FileNotFoundException e){
System.out.println("Client was unable find file: "+e);
}
// for the server
int small_buf_size = 1024;
try{
InputStream is = serversocket.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is,small_buf_size);
try{
FileOutputStream os = new FileOutputStream("c:\\tmp\\myfile.cpy");
BufferedOutputStream bos = new BufferedOutputStream(os);
byte[] buf = new byte[small_buf_size];
int count;
while (( count = bis.read(buf))>0){
bos.write(buf,0,count);
}
bos.flush();
bos.close();
}
catch(FileNotFoundException e){
System.out.println("Server was unable save file: "+e);
}
bis.close();
}
catch (IOException e){
System.out.println("Server unable to transmit: "+e);
}
Technical Details
Message-ID:
<7mkrbg$5e315@forums.borland.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<7mkkpf$5ej5@forums.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,405a4e9fa22d3496 X-Google-Attributes: gidf74b3,public From: "Mica Cooper" <micac@datatrade.com.removethis> Subject: Re: Looking for source for transfering binary files via socket Date: 1999/07/15 Message-ID: <7mkrbg$5e315@forums.borland.com> X-Deja-AN: 501343958 References: <7mkkpf$5ej5@forums.borland.com> Organization: Another Netscape Collabra Server User X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 Newsgroups: borland.public.jbuilder.java.language