I hope you guys can help me out...
i have a little applet which caused me lot of problems.
i'm new to java and i hardly managed to put all the code together,
what does the script? here:
users visit my website, and from their account they can upgrade a driver and some files for one game.
the script works well on windows XP, and when it comes to Windows Vista or Windows 7 i gate a stupid error. here is the error:
Ignored exception: java.lang.NullPointerException
Ignored exception: java.lang.NullPointerException
java.io.FileNotFoundException: C:\Program Files\Drivers (Access is denied)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
at fontapplet.fileUrl(fontapplet.java:81)
at fontapplet.fileDownload(fontapplet.java:65)
at fontapplet.start(fontapplet.java:18)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionR unnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
java.lang.NullPointerException
at fontapplet.fileUrl(fontapplet.java:96)
at fontapplet.fileDownload(fontapplet.java:65)
at fontapplet.start(fontapplet.java:18)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionR unnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Exception: java.lang.NullPointerException
Windows 7 / vista users with User Account Control (UAC) turned off can run and execute the applet correctly.
All Windows 7 / vista users which get this error, if they run Internet Explorer by using the "Run As Administrator" funciton, they also can run and execute the application.
So i want all the users to be able to run and execute the application, without getting the stupid Access is denied error.
here is the piece of code i wrote:
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
public class myapplet extends Applet {
public void init(){
}
public void start(){
String DestDir="";
String GetFile="http://www.mywebsite:80/magicdriver.inf";
boolean errorControl = checkDir("C:/temp");
DestDir="C:/Program Files/drivers/";
if(checkDir(DestDir)){
fileDownload(GetFile,DestDir);
}
loadPage();
}
public void fileDownload(String fAddress, String destinationDir){
int slashIndex =fAddress.lastIndexOf('/');
int periodIndex =fAddress.lastIndexOf('.');
String fileName=fAddress.substring(slashIndex + 1);
if (periodIndex >=1 && slashIndex >= 0 && slashIndex < fAddress.length()-1){
fileUrl(fAddress,fileName,destinationDir);
}
else{
System.err.println("path or file name.");
}
}
public void fileUrl(String fAddress, String localFileName, String destinationDir) {
OutputStream outStream = null;
URLConnection uCon = null;
InputStream is = null;
try {
URL Url;
byte[] buf;
int ByteRead,ByteWritten=0;
Url= new URL(fAddress);
outStream = new BufferedOutputStream(new FileOutputStream(destinationDir+"\\"+localFileName));
uCon = Url.openConnection();
is = uCon.getInputStream();
buf = new byte[1024];
while ((ByteRead = is.read(buf)) != -1) {
outStream.write(buf, 0, ByteRead);
ByteWritten += ByteRead;
}
}
catch (Exception e) {
e.printStackTrace();
}
finally {
try {
is.close();
outStream.close();
}
catch (IOException e) {
e.printStackTrace();
}
}
}
private void loadPage() {
try {
this.getAppletContext().showDocument(new URL("http://www.mywebsite.com/members/thankyou.php"));
}
catch (Exception e) {
e.printStackTrace();
}
}
public boolean checkDir(String fAddress) {
File filePath = new File(fAddress);
boolean success = filePath.isDirectory();
if (success){
return true;
}else{
return false;
}
}
}
here is the applet code in html:
<applet code="myapplet.class" archive="myapplet.jar" width="100px" height="50px">
<param name="progressbar" value="true" />
<PARAM NAME="java_type" VALUE="application/x-java-applet;jpi-version=1.7.0">
<param name="progresscolor" value="102,102,102" />
<param name="boxmessage" value="Loading..." />
<hr>
<strong><center>You need to have Java installed to view this page! <a href="http://www.java.com/en/download/manual.jsp">[Java download page]</a></strong></center>
<hr>
</APPLET>
Please i'd like to fix it, but i don't know how. if there is anything wrong with it please tell me.
What to do?