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.>

