• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Copy file using RandomAccessFile?

 
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
 
It's never done THAT before. Explain it to me tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic