The moose likes Applets and the fly likes Copy file using RandomAccessFile? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Applets
Reply Bookmark "Copy file using RandomAccessFile?" Watch "Copy file using RandomAccessFile?" New topic
Author

Copy file using RandomAccessFile?

Simon Xu
Ranch Hand

Joined: Aug 16, 2000
Posts: 235
hi,
I use RandomAccessFile to save a file to local machine (which is same as the server machine). I also use PrivilegeManager to allow save file into local machine. But it wont work (nothing happens in the directory). Please help, Thanx.
a part of code is enclosen here
import java.applet.Applet;
import java.awt.*;
import java.io.*;
import java.lang.reflect.*;
import java.net.*;
import java.awt.event.*;
import netscape.security.*;
public class BrowseInt extends Applet implements ActionListener {
.....
boolean saveFile (String sourceFileString, String destFileString) {
char ch;
RandomAccessFile sourceFile = null;
RandomAccessFile destFile = null;
try {
sourceFile = new RandomAccessFile(sourceFileString, "r");
destFile = new RandomAccessFile(destFileString, "rw");
}
catch (IOException exception) {
return false;
}
/* Save the class file */
try
{
PrivilegeManager.enablePrivilege ("UniversalFileAccess");
try
{
while ((ch = (char)sourceFile.readChar())!='\n')
destFile.writeChar(ch);
}
catch (SecurityException e)
{
new MessageBox("BROWSE INTERFACE", "WriteFile\n: caught SecurityException");
return false;
}
catch (IOException ioe)
{
new MessageBox("BROWSE INTERFACE", "WriteFile\n: caught IOException");
return false;
}

PrivilegeManager.revertPrivilege ("UniversalFileAccess");

}
catch(ForbiddenTargetException fte)
{
new MessageBox("BROWSE INTERFACE", "WriteFile\n: caught ForbiddenTargetException");
return false;
}
return true;
}
}
Simon Xu
Ranch Hand

Joined: Aug 16, 2000
Posts: 235
any help? Thanks
Simon Xu
Ranch Hand

Joined: Aug 16, 2000
Posts: 235
hi,
I finally change to DataOutputStream. It works! But I dont know why RandomAccessFile wont work.
Simon
 
IntelliJ Java IDE
 
subject: Copy file using RandomAccessFile?
 
Threads others viewed
UNIX file delivery failed: Map failed
Please Help!!!
FTP Upload
Writing to a file
what is ForbiddenTargetException?
developer file tools

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture