Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8854391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:52:12+00:00 2026-06-14T13:52:12+00:00

I ran into a weird problem, and i was wondering if anyone has an

  • 0

I ran into a weird problem, and i was wondering if anyone has an idea what could be the cause. I’m reading in a file ( a small exe of 472 KB ) with FileInputStream, i plan to send the file torugh RMI connection, and i had an idea, where i could show the upload’s % based on how much have i already sent trough compared to the overall length of the file.

First i tried it out locally and i couldn’t get it work. Here is an example, what i was doing.

FileInputStream fileData = new FileInputStream(file);
reads = new ArrayList<Integer>();
buffers = new ArrayList<byte[]>();
int i = 0;
while ( (read = fileData.read(buffer)) > 0) {
      System.out.println("Run : " + (i + 1));
      outstreamA.write(buffer, 0, read);
      reads.add(read);
      buffers.add(buffer);
      outstreamB.write(this.buffers.get(i), 0, this.reads.get(i));
      i = i + 1;
}

This two FileOutputStream creates two files ( same ones just with different name ), works fine. However, when i’m not using fileData.read() but any other for / while, it just dosen’t work. It creates the exact same file ( length is exactly the same ) but my Window cannot run the exe, i get an error message :
“The version of this file is not compatible with the version of Windows you’re running…”.

This is how i tried:

//for (int i = 0; i < buffers.size(); ++i) {
  i = 0;
//while ( (read = fileData2.read(buffer)) > 0) {
  while ( i < size) {
      System.out.println("Run#2 : " + (i + 1));
      outstreamC.write(this.buffers.get(i), 0, this.reads.get(i));
      i = i + 1;
  }

fileData2 is the same as fileData. If i work with fileData2.read(buffer), outstreamC creates a working file aswell.

It dosen’t matter if i run with for till the list’s size, or till “size” which equals the time i entered the first while. There is something missing, and i cannot figure it out.

The weird thing is, outstreamB creates a working file, yet outstreamC cannot, but they working with the exact same items.

Originally i was planning to pass the “read” and “buffer” each time i entered the first while trough RMI connection, and put everything together on the other side, after all the parts arrived, but now my plan is kinda dead. Anyone has maybe an idea, how could i solve this, or achieve something similar to be able to send files trough RMI?

Best regards,
Mihaly

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T13:52:13+00:00Added an answer on June 14, 2026 at 1:52 pm

    Your code can never work. You are reading into the same buffer repeatedly and adding the same buffer to a list. So the list contains several copies of the final data you read. You would need to allocate a new buffer every time around the loop.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ran into some weird behaviour and wondering if anyone else can confirm what I
I was wondering if anyone else ran into the problem where jQuery scripts such
I ran into a weird problem. I built a mysql database where the user
I ran into a very weird problem today. Long story short, my function returns
I ran into a weird problem while trying to build a Traits GUI that
I've ran into a really weird problem. I am building a heavily distributed application
Today I ran into a weird problem. I have a database in SQL Server
I've ran into a weird problem while trying to send a JSON command to
Hi Experts of the world, I ran into a very weird problem: I am
i ran into this wierd problem: the $myImg variable has been extracted from some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.