This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of Darcy DeClute's Scrum Master Certification Guide: The Definitive Resource for Passing the CSM and PSM Exams and have Darcy DeClute on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

Cannot download the whole text file

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67735
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67735
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
 
Bear Bibeault
Sheriff
Posts: 67735
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67735
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you debugged your loop as I suggested?
 
Andrew Watson
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
I don't like that guy. The tiny ad agrees with me.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic