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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:54:54+00:00 2026-05-26T09:54:54+00:00

I am writing an updater. I have this code: package main; import java.io.*; import

  • 0

I am writing an updater. I have this code:

package main;
import java.io.*;
import java.net.*;
import java.util.*;
import java.util.regex.Pattern;
import java.lang.*;

import static java.lang.System.out;
public class UpdaterCore
{
public static void main(String args[]) throws IOException
{
    java.io.BufferedInputStream inv = new java.io.BufferedInputStream(new

                    java.net.URL("http://unicombox.tk/update/nv").openStream());
                    java.io.FileOutputStream fosv = new java.io.FileOutputStream("nv");
                    java.io.BufferedOutputStream boutv = new BufferedOutputStream(fosv,1024);
                    byte data[] = new byte[1024];
                    while(inv.read(data,0,1024)>=0)
                    {
                    boutv.write(data);
                    }
                    boutv.close();
                    inv.close();
                    //end version download

                    Scanner VersionReader= new Scanner(new File ("v")).useDelimiter(",");
                    int currentVersion= VersionReader.nextInt();
                    VersionReader.close();

                    Scanner NewVersionReader= new Scanner(new File ("nv")).useDelimiter(",");
                    int newVersion= NewVersionReader.nextInt();
                    NewVersionReader.close();



                    if (newVersion>currentVersion){


                    java.io.BufferedInputStream in = new java.io.BufferedInputStream(new

                                    java.net.URL("http://unicombox.tk/update/update.zip").openStream());
                    java.io.FileOutputStream fos = new java.io.FileOutputStream("update.zip");
                    java.io.BufferedOutputStream bout = new BufferedOutputStream(fos,1024);
                    byte data1[] = new byte[1024];
                    while(in.read(data1,0,1024)>=0)
                    {
                            bout.write(data1);
                    }
                    bout.close();
                    in.close();
                    out.println("Update successfully downloaded!");

                    }

                    else{
                            out.println("You have the latest version!");
                    }








}
}

It gets the new version from a server, and then compares it to its current version. If the new version is greater than the current version, it downloads the update.

I am having one big problem. My program can never find the files “v” and “nv”!
“v” and “nv” are in the same folder as the compiled jar, yet I get a FileNotFound.
What am I doing wrong?

  • 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-05-26T09:54:54+00:00Added an answer on May 26, 2026 at 9:54 am

    Get path to current directory (directory where the .jar file is placed) like this:

    // import java.io.*;
    // import java.net.URLDecoder;
    // throws java.io.UnsupportedEncodingException 
    
        String path = UpdaterCore.class.getProtectionDomain().getCodeSource().getLocation().getPath();
        String decodedPath = URLDecoder.decode(path, "UTF-8");
        System.out.println(decodedPath);
    

    and then create File instance like this

    new File (decodedPath + File.separatorChar + "v")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing some Javascript code for an ASP.net page. I have the string foo
I have a table that has about 400,000+ rows. I am writing some pattern
I have some file writing code that works as expected, but prints an error
I am not sure if I am writing this code correctly. Fruit * o1
I'm not sure if this is the most optimal way of writing this code,
I have this code: $fp = fopen($unenc_path, w); fwrite($fp, $msg); fclose($fp); $easy_access_emails = 'person@##.com';
how to enable the writing to file befor closing it , i have this
I am writing a software package whose job is to export DB data from
**Hello, I'm trying to create an archiver in java. This means that I am
I have a list of string that I am writing out to a CSV

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.