hi,
im working on java on some client server project...
in the project the client and the server can send files, but im failng to do so, the resiver get only part of the file...
here is my code
sender:
public void uploadByteFile(String fileNameToGet, File fileDst)
{
try
{
FileReader fileReader = new FileReader(new File("c:\\7.mpg"));
BufferedReader bufferedFileReader = new BufferedReader(fileReader);
// PrintWriter streamWriter = new PrintWriter(client.getOutputStream());
DataOutputStream streamWriter = new DataOutputStream(client.getOutputStream());
String line = null;
PrintWriter outTextStream = new PrintWriter(client
.getOutputStream(), true);
BufferedReader in = new BufferedReader(new InputStreamReader(client
.getInputStream()));
outTextStream.println("start?");
if (in.readLine().matches("start"))
{
streamWriter.flush();
// streamWriter.flush();
while ((line = bufferedFileReader.readLine()) != null)
{
streamWriter.writeBytes(line);
// System.out.println(line);
}
out.flush();
}
//in.close();
}
catch (IOException e)
{
System.out.println("Error reading from file: " + fileNameToGet);
}
finally
{
if (out != null)
{
try
{
out.close();
}
catch (IOException e)
{
System.out.println("Error wile trying to close a file: "
+ fileDst.getName());
e.printStackTrace();
}
}
}
}
resiver::
FileOutputStream out = null;
try
{
PrintWriter outTextStream = new PrintWriter(socket
.getOutputStream(), true);
BufferedReader inTextStream = new BufferedReader(
new InputStreamReader(socket.getInputStream()));
out = new FileOutputStream("c:\\91.mpg");
int received = 0;
byte[] buff = new byte[1024];
int sum = 0;
inTextStream.readLine();
outTextStream.println(("start"));
DataInputStream in = new DataInputStream(socket.getInputStream());
while ((received = in.read(buff)) > 0)
{
out.write(buff, 0, received);
System.out.println(sum += buff.length);
}
out.flush();
out.close();
in.close();
in.close();
// out = new FileOutputStream("");
out.close();
out.flush();
out = null;
}
catch (IOException e)
{
System.out.println("Error reading from file: ");
}
finally
{
if (out != null)
{
try
{
out.close();
}
catch (IOException e)
{
System.out.println("Error wile trying to close a file: ");
e.printStackTrace();
}
}
}
help....