public class filewrite {
public static void main(String ar[]){
try{
BufferedReader br=new BufferedReader(new FileReader(new File("database.txt")));
BufferedWriter br2=new BufferedWriter(new FileWriter(new File("database1.txt")));
String st;
while((st=br.readLine())!=null){
br2.write(st+"n");
}
}
catch(IOException e){}
}
}
没有错误或警告,但它仍然无法将数据从"database.txt"复制到"database1.txt">
请帮忙。提前感谢
您需要告诉它允许特权操作。使用AccessController。试试这个:
public void start() {
AccessController.doPrivileged(new PrivilegedAction<Object>(){
@Override
public Object run() {
try{
BufferedReader br=new BufferedReader(new FileReader(new File("database.txt")));
BufferedWriter br2=new BufferedWriter(new FileWriter(new File("database1.txt")));
String st;
while((st=br.readLine())!=null){
String []str=st.split(";");
br2.write(st+"n");
}
}
catch(IOException e){}
//catch your exceptions
}
}
});
}