🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #15043

Problems w/ code to transfer file

#15043
From: Darrel Davis
Date: Tue, 13 Jul 1999 00:00
47 lines
1971 bytes
I'm a Java newbie in the middle of developing server-side code
that transfers files to/from clients.  The clients send files and this
method gets called.  Notice that I know the size of the file from
the input parameters.

With this code, I seem to get the file but it is corrupted and not
the correct number of bytes (always on the too big side).  These
are sound files which makes it quite noticeable.  I'm sure the problem
is simple for this group and any help is appreciated.


import java.io.*;
import java.net.*;

public getFile (String sFileName, DataInputStream in, int iFileSize ) {

    DataOutputStream f_out;
    private static final int MAXBLOCK = 1024;

    byte[] fileArray = new byte[MAXBLOCK];
    try {
      f_out = new DataOutputStream(new BufferedOutputStream (new
FileOutputStream(sFileName)));
      System.out.println("iFileSize = " + iFileSize);
      int iCnt = 0;
      int iTot = 0;               // current byte count
      // first read
      iCnt = in.read(fileArray);
      f_out.write(fileArray);
      iTot += iCnt;

      System.out.println("Getting file: ");

      while ( iTot < iFileSize ) {
        iCnt = in.read(fileArray);
        f_out.write(fileArray);
        iTot += iCnt;
        System.out.print(".");          // print a dot (.) per 1k
      }

      System.out.println();
      f_out.flush();
      f_out.close();
  } catch (Exception e) {
      e.printStackTrace();
  }
}
Technical Details
Message-ID: <7mg96v$1863@forums.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,227e1d885d7026d9,start
X-Google-Attributes: gidf74b3,public
From: "Darrel Davis" <darreld@his.com>
Subject: Problems w/ code to transfer file
Date: 1999/07/13
Message-ID: <7mg96v$1863@forums.borland.com>
X-Deja-AN: 500663357
X-Priority: 3
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2014.211
Organization: Another Netscape Collabra Server User
X-MSMail-Priority: Normal
Newsgroups: borland.public.jbuilder.java.language