File transfer problem

Hi, I'm having a problem with file transferring, the aim is to transfer files from one machine, server, to others connected, it goes like:

Server:

.....

.....

String fileName = file.getPath().toString();

//

String fName = file.getName();

//

FileInputStream fis = new FileInputStream(fileName);

//

send(fileName, fName);

.....

.....

//function send

......

......

//

FileInputStream fis = new FileInputStream(filename);

//

BufferedInputStream in = new BufferedInputStream(fis);

BufferedOutputStream out = new BufferedOutputStream( Server.connection.getOutputStream() ); //Server is another class that has all // the connection streaming and processing

//

fname=fname+"}";

//

byte[] name=fname.getBytes();

//

for(int i=0;i<name.length;i++)

{

out.write(name);

}

//

int i;

//

while ((i = in.read()) != -1)

{

out.write(i);

}

//

out.flush();

//

return true;

Client:

.......

.......

try

{

char j=0;

//

while((j =(char)in.read()) != '}')

{

receivedFile = receivedFile+j;

}

//

FileOutputStream fos = new FileOutputStream(receivedFile);

//

output = new BufferedOutputStream(fos);

//

int i;

//

while ((i = input.read()) != -1)

{

output.write(i);

//

System.out.println("Receiving data...");

}

//

receivedFile = "C:\\";

//

output.flush();

//

input.close();

//

output.close();

//

socket.close();

//

System.out.println("Transfer complete.");

}

Im having 2 problems, the first is that the logic seems good, maybe not perfect but i think its good, but the application is not working.

The second problem is that the client is receiving text packets, on the outputStream, so an exception always happens.>

[2085 byte] By [Omar_Sayyeda] at [2007-11-27 3:23:43]
# 1
The reader will block until the sender closes the output stream. If you can't close the output stream you have to send the file size in advance and have the reader stop reading at that number of bytes.You can't receive text blocks on an output stream, this makes no sense.
ejpa at 2007-7-12 8:26:30 > top of Java-index,Core,Core APIs...