Thread: Auto-Updating

Results 1 to 9 of 9
  1. #1 Auto-Updating 
    Expert Programmer


    Join Date
    Dec 2007
    Posts
    2,018
    Thanks given
    52
    Thanks received
    84
    Rep Power
    986
    Hey people, could anybody fix this for me? I get this error when I compile , If any of you guys fix ill release auto server updating when you restart I just cant seem to fix this class...

    Code:
    Update.java:126: not a statement
            exception;
            ^
    1 error
    Press any key to continue . . .
    Code:
    import java.io.*;
    import java.net.URL;
    import java.net.URLConnection;
    import java.util.Enumeration;
    import java.util.zip.ZipEntry;
    import java.util.zip.ZipFile;
    
    public class Update extends Thread
    {
    
        private String homeDir;
        private String saveAs;
        private String urlLoc;
        private boolean checkProgress;
    
        public static void main(String args[])
        {
        }
    
        public Update(String s, String s1, String s2)
        {
            homeDir = s2;
            saveAs = (new StringBuilder()).append(s2).append(s1).toString();
            urlLoc = s;
            if(!(new File(s2)).exists())
            {
                (new File(s2)).mkdir();
            }
            if(downloadFile())
            {
                unZipFile();
                deleteFile();
            } else
            {
                System.out.println("error");
                deleteFile();
            }
        }
    
        private void writeStream(InputStream inputstream, OutputStream outputstream)
            throws IOException
        {
            byte abyte0[] = new byte[1024];
            int i;
            while((i = inputstream.read(abyte0)) >= 0) 
            {
                outputstream.write(abyte0, 0, i);
            }
            inputstream.close();
            outputstream.close();
        }
    
        private void unZipFile()
        {
            try
            {
                ZipFile zipfile = new ZipFile(saveAs);
                for(Enumeration enumeration = zipfile.entries(); enumeration.hasMoreElements();)
                {
                    ZipEntry zipentry = (ZipEntry)enumeration.nextElement();
                    if(zipentry.isDirectory())
                    {
                        if(checkProgress)
                        {
                            System.out.println((new StringBuilder()).append("Creating Directory: ").append(zipentry.getName()).toString());
                        }
                        (new File((new StringBuilder()).append(homeDir).append(zipentry.getName()).toString())).mkdir();
                    } else
                    {
                        if(checkProgress)
                        {
                            System.out.println((new StringBuilder()).append("Extracting File: ").append(zipentry.getName()).toString());
                        }
                        writeStream(zipfile.getInputStream(zipentry), new BufferedOutputStream(new FileOutputStream((new StringBuilder()).append(homeDir).append(zipentry.getName()).toString())));
                    }
                }
    
                zipfile.close();
            }
            catch(Exception exception)
            {
                exception.printStackTrace();
            }
        }
    
        private void deleteFile()
        {
            try
            {
                File file = new File(saveAs);
                file.delete();
            }
            catch(Exception exception)
            {
                exception.printStackTrace();
            }
        }
    
        private boolean downloadFile()
        {
            long l;
            File file;
            if(checkProgress)
            {
                System.out.println((new StringBuilder()).append("Downloading ").append(saveAs).append("...").toString());
            }
            URLConnection urlconnection = (new URL(urlLoc)).openConnection();
            urlconnection.setRequestProperty("User-Agent", "Mozilla");
            l = urlconnection.getContentLength();
            FileOutputStream fileoutputstream = new FileOutputStream(saveAs);
            BufferedOutputStream bufferedoutputstream = new BufferedOutputStream(fileoutputstream);
            writeStream(urlconnection.getInputStream(), bufferedoutputstream);
            fileoutputstream.close();
            bufferedoutputstream.close();
            file = new File(saveAs);
            if(l != file.length())
            {
                return false;
            }
            if(checkProgress)
            {
                System.out.println((new StringBuilder()).append(saveAs).append(" downloaded...").toString());
            }
            return true;
            Exception exception;
            exception;
            System.out.println(exception);
            return false; 
        }
    }
     

  2. #2  
    Respected Member


    Luke132's Avatar
    Join Date
    Dec 2007
    Age
    32
    Posts
    12,549
    Thanks given
    177
    Thanks received
    5,784
    Discord
    View profile
    Rep Power
    5000
    Code:
    import java.io.*;
    import java.net.URL;
    import java.net.URLConnection;
    import java.util.Enumeration;
    import java.util.zip.ZipEntry;
    import java.util.zip.ZipFile;
    
    public class Update extends Thread
    {
    
        private String homeDir;
        private String saveAs;
        private String urlLoc;
        private boolean checkProgress;
    
        public static void main(String args[])
        {
        }
    
        public Update(String s, String s1, String s2)
        {
            homeDir = s2;
            saveAs = (new StringBuilder()).append(s2).append(s1).toString();
            urlLoc = s;
            if(!(new File(s2)).exists())
            {
                (new File(s2)).mkdir();
            }
            if(downloadFile())
            {
                unZipFile();
                deleteFile();
            } else
            {
                System.out.println("error");
                deleteFile();
            }
        }
    
        private void writeStream(InputStream inputstream, OutputStream outputstream)
            throws IOException
        {
            byte abyte0[] = new byte[1024];
            int i;
            while((i = inputstream.read(abyte0)) >= 0) 
            {
                outputstream.write(abyte0, 0, i);
            }
            inputstream.close();
            outputstream.close();
        }
    
        private void unZipFile()
        {
            try
            {
                ZipFile zipfile = new ZipFile(saveAs);
                for(Enumeration enumeration = zipfile.entries(); enumeration.hasMoreElements();)
                {
                    ZipEntry zipentry = (ZipEntry)enumeration.nextElement();
                    if(zipentry.isDirectory())
                    {
                        if(checkProgress)
                        {
                            System.out.println((new StringBuilder()).append("Creating Directory: ").append(zipentry.getName()).toString());
                        }
                        (new File((new StringBuilder()).append(homeDir).append(zipentry.getName()).toString())).mkdir();
                    } else
                    {
                        if(checkProgress)
                        {
                            System.out.println((new StringBuilder()).append("Extracting File: ").append(zipentry.getName()).toString());
                        }
                        writeStream(zipfile.getInputStream(zipentry), new BufferedOutputStream(new FileOutputStream((new StringBuilder()).append(homeDir).append(zipentry.getName()).toString())));
                    }
                }
    
                zipfile.close();
            }
            catch(Exception exception)
            {
                exception.printStackTrace();
            }
        }
    
        private void deleteFile()
        {
            try
            {
                File file = new File(saveAs);
                file.delete();
            }
            catch(Exception exception)
            {
                exception.printStackTrace();
            }
        }
    
        private boolean downloadFile()
        {
            long l;
            File file;
            if(checkProgress)
            {
                System.out.println((new StringBuilder()).append("Downloading ").append(saveAs).append("...").toString());
            }
            URLConnection urlconnection = (new URL(urlLoc)).openConnection();
            urlconnection.setRequestProperty("User-Agent", "Mozilla");
            l = urlconnection.getContentLength();
            FileOutputStream fileoutputstream = new FileOutputStream(saveAs);
            BufferedOutputStream bufferedoutputstream = new BufferedOutputStream(fileoutputstream);
            writeStream(urlconnection.getInputStream(), bufferedoutputstream);
            fileoutputstream.close();
            bufferedoutputstream.close();
            file = new File(saveAs);
            if(l != file.length())
            {
                return false;
            }
            if(checkProgress)
            {
                System.out.println((new StringBuilder()).append(saveAs).append(" downloaded...").toString());
            }
            return true;
            Exception exception;
            System.out.println(exception);
            return false; 
        }
    }

     

  3. #3  
    Expert Programmer


    Join Date
    Dec 2007
    Posts
    2,018
    Thanks given
    52
    Thanks received
    84
    Rep Power
    986
    Nope Good try though got these errors

    Code:
    Update.java:125: unreachable statement
            Exception exception;
                      ^
    Update.java:126: variable exception might not have been initialized
            System.out.println(exception);
                               ^
    Update.java:107: unreported exception java.net.MalformedURLException; must be ca
    ught or declared to be thrown
            URLConnection urlconnection = (new URL(urlLoc)).openConnection();
                                           ^
    Update.java:107: unreported exception java.io.IOException; must be caught or dec
    lared to be thrown
            URLConnection urlconnection = (new URL(urlLoc)).openConnection();
                                                                          ^
    Update.java:110: unreported exception java.io.FileNotFoundException; must be cau
    ght or declared to be thrown
            FileOutputStream fileoutputstream = new FileOutputStream(saveAs);
                                                ^
    Update.java:112: unreported exception java.io.IOException; must be caught or dec
    lared to be thrown
            writeStream(urlconnection.getInputStream(), bufferedoutputstream);
                                                    ^
    Update.java:112: unreported exception java.io.IOException; must be caught or dec
    lared to be thrown
            writeStream(urlconnection.getInputStream(), bufferedoutputstream);
                       ^
    Update.java:113: unreported exception java.io.IOException; must be caught or dec
    lared to be thrown
            fileoutputstream.close();
                                  ^
    Update.java:114: unreported exception java.io.IOException; must be caught or dec
    lared to be thrown
            bufferedoutputstream.close();
                                      ^
    Note: stream.java uses or overrides a deprecated API.
    Note: Recompile with -Xlint:deprecation for details.
    9 errors
    Press any key to continue . . .
     

  4. #4  
    Toonscape
    Guest
    just delete the exception?>
     

  5. #5  
    Optimist

    Vice's Avatar
    Join Date
    Nov 2007
    Age
    25
    Posts
    3,263
    Thanks given
    3
    Thanks received
    59
    Rep Power
    2536
    dont help if you don't know what the hell your talking about toonscape
    Jack
    Scotland
    Undergraduate - BSc Computing Science
     

  6. #6  
    Ian...
    Guest
    LOL u need to import java.io.*; LMAO
     

  7. #7  
    Expert Programmer


    Join Date
    Dec 2007
    Posts
    2,018
    Thanks given
    52
    Thanks received
    84
    Rep Power
    986
    Quote Originally Posted by Ian... View Post
    LOL u need to import java.io.*; LMAO
    Nope, Already have
     

  8. #8  
    Ian...
    Guest
    change all exeptions to java.io.exeption then...
     

  9. #9  
    mrdek11
    Guest
    Those must be caught errors are saying you need to put those parts in try-catch statements.
    Code:
    import java.io.*;
    import java.net.URL;
    import java.net.URLConnection;
    import java.util.Enumeration;
    import java.util.zip.ZipEntry;
    import java.util.zip.ZipFile;
    
    public class Update extends Thread
    {
    
        private String homeDir;
        private String saveAs;
        private String urlLoc;
        private boolean checkProgress;
    
        public static void main(String args[])
        {
        }
    
        public Update(String s, String s1, String s2)
        {
            homeDir = s2;
            saveAs = (new StringBuilder()).append(s2).append(s1).toString();
            urlLoc = s;
            if(!(new File(s2)).exists())
            {
                (new File(s2)).mkdir();
            }
            if(downloadFile())
            {
                unZipFile();
                deleteFile();
            } else
            {
                System.out.println("error");
                deleteFile();
            }
        }
    
        private void writeStream(InputStream inputstream, OutputStream outputstream)
            throws IOException
        {
            byte abyte0[] = new byte[1024];
            int i;
            while((i = inputstream.read(abyte0)) >= 0) 
            {
                outputstream.write(abyte0, 0, i);
            }
            inputstream.close();
            outputstream.close();
        }
    
        private void unZipFile()
        {
            try
            {
                ZipFile zipfile = new ZipFile(saveAs);
                for(Enumeration enumeration = zipfile.entries(); enumeration.hasMoreElements();)
                {
                    ZipEntry zipentry = (ZipEntry)enumeration.nextElement();
                    if(zipentry.isDirectory())
                    {
                        if(checkProgress)
                        {
                            System.out.println((new StringBuilder()).append("Creating Directory: ").append(zipentry.getName()).toString());
                        }
                        (new File((new StringBuilder()).append(homeDir).append(zipentry.getName()).toString())).mkdir();
                    } else
                    {
                        if(checkProgress)
                        {
                            System.out.println((new StringBuilder()).append("Extracting File: ").append(zipentry.getName()).toString());
                        }
                        writeStream(zipfile.getInputStream(zipentry), new BufferedOutputStream(new FileOutputStream((new StringBuilder()).append(homeDir).append(zipentry.getName()).toString())));
                    }
                }
    
                zipfile.close();
            }
            catch(Exception exception)
            {
                exception.printStackTrace();
            }
        }
    
        private void deleteFile()
        {
            try
            {
                File file = new File(saveAs);
                file.delete();
            }
            catch(Exception exception)
            {
                exception.printStackTrace();
            }
        }
    
        private boolean downloadFile()
        {
    try{
            long l;
            File file;
            if(checkProgress)
            {
                System.out.println((new StringBuilder()).append("Downloading ").append(saveAs).append("...").toString());
            }
            URLConnection urlconnection = (new URL(urlLoc)).openConnection();
            urlconnection.setRequestProperty("User-Agent", "Mozilla");
            l = urlconnection.getContentLength();
            FileOutputStream fileoutputstream = new FileOutputStream(saveAs);
            BufferedOutputStream bufferedoutputstream = new BufferedOutputStream(fileoutputstream);
            writeStream(urlconnection.getInputStream(), bufferedoutputstream);
            fileoutputstream.close();
            bufferedoutputstream.close();
            file = new File(saveAs);
            if(l != file.length())
            {
                return false;
            }
            if(checkProgress)
            {
                System.out.println((new StringBuilder()).append(saveAs).append(" downloaded...").toString());
            }
            return true;
    }catch(EXception e){e.printStackTrace();}
            return false; 
        }
    }
    I likely missed some parts, but that should give you an idea what you need to do.
    Good luck
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •