• Post Reply Bookmark Topic Watch Topic
  • New Topic

help me,about DataInputStream

 
z meng
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want get database file from a server,server send me data content include:
200 ok(express file exit)
FILESIZE 1496124(database file size)
db file i want follow
below is my code:

size of db file i get is 1496124
but my program always print echo=1481292 or echo=1487139 and suspend,many time like this,
thank you opinion
[ August 31, 2003: Message edited by: jason adam ]
 
Chris Fetterley
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had a problem similar to this when I was doing a .xls output. The problem might be memory exception with the file size you are working with. try shrinking the amount you are trying to read to a specific amount of records at a time. I believe that should help you.
 
Idly Vada
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Man u made a silly mistake in ur code
Your class name is getTar and you have a method named public void getTar()
Note that the method name and the class name are same.Java is treatng your method getTar as constuctor. You should not have return type for a constructor.This is the reason behind the problem.
I think u got it
Always keep java naming conventions in mind. Your class name should be GetTar and not getTar
 
Wayne L Johnson
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Having a class named "getJar" with a method named "getJar" is a poor design, but shouldn't cause the problem "z meng" is experiencing. Java is smart enough to realize that the "getJar()" method is NOT a constructor, and will work despite the poor choice of naming.
A more likely culprit is with the FTP protocol itself. FTP works in two modes: "bin" (binary) and "asc" (ascii). If you use bin, it will bring the file across "as is", byte-by-byte. If you use asc, it will try and translate end-of-line characters appropriately for the machines it is transferring to. Transferring files between different OS-es (such as UNIX and Windows) will usually change the file size since the end-of-line character(s) are different. You should use the "asc" mode only for ascii (text) files.
Since you are trying to transfer a binary file, you need to make sure you are doing a binary transfer. Some FTP servers default to "bin" mode, other default to "asc" mode. To force a binary transfer, you need to issue the "bin" (or "binary") command before doing the "get". This should solve your problem.
Good luck!
[ September 08, 2003: Message edited by: Wayne L Johnson ]
 
Idly Vada
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think z meng is using FTP from his socket declaration
echoSocket = new Socket("192.168.0.111", 2001)
But point raised by Wayne L Johnson is a valid point. In case of FTP if request is valid and after issuing pasv command, the server will send data port(which is not its default data port) and to waits for a connection and sends a response .The response includes the host and port address this server is listening on.
 
Wayne L Johnson
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think z meng is using FTP from his socket declaration
echoSocket = new Socket("192.168.0.111", 2001)

Murthy is correct since the default port for FTP is 21; I should have been included that assumption in my initial reply.
The reason I focused on "FTP" is because after making a socket connection, the code issues a "get ...", which is an FTP command, and because the problem described could be explained by the bin/ascii modes in FTP.
If "FTP" is being used, then issuing a "bin" command prior to the "get" should solve it. If some other protocol is being used, we need to know what it is. It may still boil down to the server doing an end-of-line character conversion which is changing the file size.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!