This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cannot download the whole text file

 
Andrew Watson
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello

I am writing servlet which is to download files to my desktop app and then save it on my hdd. I have tested the code and it works fine for binary files like video ot images or even doc files but it doesn't work with txt. It looses text.

Here is the problem code:



For example I have just downloaded a txt file so its original length is 1722bytes but the downloaded version contains 1696bytes ... So where I could lost its final 26 bytes ? I suspect the final chunk occures the problem but I don't know how to fix it. Please help


Any useful comment is appreciated.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you compared the files? Could the difference be perhaps in how lines are terminated?
 
Andrew Watson
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Have you compared the files? Could the difference be perhaps in how lines are terminated?


Yes, I opened it and watched its content... I don't know why but I get lost the final bytes Please help me to understand why
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you are actually missing characters at the end of the file? Not just comparing lengths?
 
Andrew Watson
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here is the original text:

I don't know when it happened.
I don't know when she came,
But, she's the one I always knew,
Grandma was her name.

She taught me how to tie my shoes.
She taught me how to talk.
And, though I can't remember,
I think she taught me how to walk.

When all the other kids in school
Would talk about Mom and Dad,
I wondered where my parents were,
That made me kinda’ sad.


here is the downloaded text:

I don't know when it happened.
I don't know when she came,
But, she's the one I always knew,
Grandma was her name.

She taught me how to tie my shoes.
She taught me how to talk.
And, though I can't remember,
I think she taught me how to walk.

When all the other kids in school
Would talk about Mom and Dad,
I wondered where my parents were,
That made



Why the code doesn't download the whole txt files ? As you can see the downloaded file missing text How to fix it?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your code indentation is all wonky, so I won't be reading the code, but check your loops to make sure that you're not dropping the last chunk on either writing or reading.
 
Andrew Watson
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David O'Meara wrote:BeForthrightWhenCrossPostingToOtherSites
http://stackoverflow.com/questions/5505418/downloaded-txt-file-become-shrinked


It is not . They don't answer for long time so maybe they simply don't know how to help me with the question. So I hope you can
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you debugged your loop as I suggested?
 
Andrew Watson
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Have you debugged your loop as I suggested?


Yes

I want to show you the decipher code:

the decipher defined the same as for encryping...:



How you think maybe there is a problem? I heard that to decrypt there should be some differ alg parameters but I am not sure...
 
Kasper Pedersen
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andrew Watson wrote:here is the original text:

I don't know when it happened.
I don't know when she came,
But, she's the one I always knew,
Grandma was her name.

She taught me how to tie my shoes.
She taught me how to talk.
And, though I can't remember,
I think she taught me how to walk.

When all the other kids in school
Would talk about Mom and Dad,
I wondered where my parents were,
That made me kinda’ sad.


here is the downloaded text:

I don't know when it happened.
I don't know when she came,
But, she's the one I always knew,
Grandma was her name.

She taught me how to tie my shoes.
She taught me how to talk.
And, though I can't remember,
I think she taught me how to walk.

When all the other kids in school
Would talk about Mom and Dad,
I wondered where my parents were,
That made



Why the code doesn't download the whole txt files ? As you can see the downloaded file missing text How to fix it?


I just noticed that you are missing the same number of characters as there are newlines in the text (suggesting some \n\r issue). Try doing the same with a text without any linebreaks ... just a thought.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic