Domanda

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){}        
   }
  } 

no error or warning, but still it can't copy the data from "database.txt" to "database1.txt"

please help. Thanks in advance

È stato utile?

Soluzione

You need to tell it to allow a privileged action. Using the AccessController. Try this:

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
            }
        }               
    });
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top