Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Copy file using RandomAccessFile?

 
Simon Xu
Ranch Hand
Posts: 235
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 235
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
any help? Thanks
 
Simon Xu
Ranch Hand
Posts: 235
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
I finally change to DataOutputStream. It works! But I dont know why RandomAccessFile wont work.
Simon
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic