I have a java applet and I need to write to a file, since I can't do that directly, I am calling a php script to write to the file. Here is the relevant code in the .java file
URL myURL=null;
URLConnection urlConn=null;
DataOutputStream printout=null;
DataInputStream input=null;
try{
myURL=new URL(getCodeBase(),"writeFromFile.php");
}catch(Exception easidghih){JOptionPane.showMessageDialog(null,"WRITETOFILE");}
try{
urlConn=myURL.openConnection();
}catch(Exception w){JOptionPane.showMessageDialog(null,"openConnection()");w.printStackTrace();}
try{urlConn.setDoInput(true);
urlConn.setUseCaches(false);
}
catch(Exception a){JOptionPane.showMessageDialog(null,"Exception here");}
try{
urlConn.setDoOutput(true);
PrintWriter out=new PrintWriter(urlConn.getOutputStream());
out.println("File="+username+"P.txt"+"&text="+(Long.toString(number)));
out.close();
the text of the php file, "writeFromFile.php" is below.
<HTML>
<BODY>
<?php
print "BOB";
$File=$_POST["File"];
$text=$_POST["text"];
$filename=$File;
$fp=fopen($filename,"w");
$string=$text;
$write=fputs($fp,$string);
fclose($fp);
?>
</BODY>
</HTML>
The file writing works fine when I have a separate file with a form to fill out in HTML. But when I run the java applet it gives no errors, but the file writing doesn't work.