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 8318179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:52:22+00:00 2026-06-08T21:52:22+00:00

I’m trying to make an auto-updating client. The jarred client will go to the

  • 0

I’m trying to make an auto-updating client. The jarred client will go to the server and ask for an update file. The server will send over the update file. When the update file(containing the jar file which has been converted into a byte array) arrives, the client will check whether it has the newest version of the client jar(the one in the update file). The reference “in” is a socket connected to the server, by the way.

UpdateFile uf = (UpdateFile) in.readObject();
System.out.println("Client checking if update needed");                                                                              
if (!uf.getVersion().equals(myVersion)) {
    System.out.println("Client needed update");
    uf.update(updateLocation);
}

If it does not have the newest jar, it will call the function update(String whereToUpdate) in UpdateFile. This will delete the old jar file(The one calling the function update()!) and replace it by writing the byte[] to the same position.

public void update(String location) {
    try {
        boolean b = (new File(location)).delete();
        System.out.println("removed old jar file");
        updateJar.writeBytes(location);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

In this code, updateJar is a NetworkingFile(my own class). This NetworkingFile pretty converts non-serializable objects into a byte[], is sent to the receiver, and writes the file back to disk.

public class NetworkingFile implements Serializable{
byte[] cArray;
String name;

public NetworkingFile(File f, String fileName) {
    name = fileName;
    compressFile(f);
}

public NetworkingFile(byte[] b, String fileName) {
    cArray = b;
    name = fileName;

}

public void compressFile(File f) {      
    cArray = new byte[(int)f.length()];

    try {
        FileInputStream inputReader = new FileInputStream(f);

        BufferedInputStream fileReader = new BufferedInputStream(inputReader);

        fileReader.read(cArray, 0, cArray.length);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

public String getFileName() {
    return name;
}

public byte[] getCompressedFile() {
    return cArray;
}

public void writeBytes(String location) {
    try {
        File writeFile = new File(location);
        FileOutputStream writer = new FileOutputStream(writeFile);

        writer.write(cArray);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
 }
}

This code doesn’t give an error when compiling or executing the FIRST jar. However, when the jar is finished updating, I quit the program and try to run it using “java -jar filename.jar”. However, I get this error on running:
Error: Invalid or corrupt jarfile DropBoxClient.jar

Any ideas on what might cause this? All help will be appreciated.

  • 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-08T21:52:24+00:00Added an answer on June 8, 2026 at 9:52 pm

    A few things here.

    The first one is that you are not closing your FileOutputStream. If you don’t close of flush it, the program may end without writing everything to disk.

    Second one, fileReader.read is not GUARANTEED to read that many bytes, for a number of reasons it may return before actually reading that much bytes. That’s why it returns an int with the number of bytes actually read. (see javadocs here)

    The recommended way for copying a file from one file to another is rather different than the one you implemented here, see for example this source code example.

    I would suggest you to read a bit more about how Java streams work, they may seem simpler than they are.

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

Sidebar

Related Questions

I am trying to render a haml file in a javascript response like so:
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.