0

this code transfers all files except office file like docx and pdf. need a fix. Files with large sizes are being transferred and are not corrupted but the problem persists with only word or pdf or powerpoint or excel files.

this is client side code

FileInputStream reader= new FileInputStream(new File(path));
byte[] buffer=new byte[512];
int count=0;
dataSendingStream.writeUTF("upload");

System.out.println(filename);
dataSendingStream.writeUTF(filename);

dataSendingStream.writeInt(count);
System.out.println(count);
do
{
    count=reader.read(buffer);
    dataSendingStream.writeInt(count);
    if(count!=-1)
        dataSendingStream.write(buffer);
    if(count!=-1)
    {
        for(int i=0;i<512;i++)
        {
            System.out.println("item "+i+" in buffer is     "+Byte.toString(buffer[i]));
        }
    }

    System.out.println(buffer);
    System.out.println(count);
}
while(count!=-1);

this is the server side code

String filename=fins.readUTF();
File file=new File("E:\\repository\\"+filename);
BufferedOutputStream writer=new BufferedOutputStream(new FileOutputStream(file));
int count=fins.readInt();
byte[] buffer=new byte[512];
while(count!=-1)
{
    System.out.println(count);
    count=fins.readInt();
    if(count==-1)
        break;
    fins.read(buffer);
    for(int i=0;i<512;i++)
        System.out.println("item "+i+" in buffer is "+Byte.toString(buffer[i]));
    writer.write(buffer);
}

writer.flush();
System.out.println("file written");
writer.close();
System.out.println("file recieved");
Pshemo
  • 122,468
  • 25
  • 185
  • 269
Maaz Asif
  • 77
  • 6

0 Answers0