[파일 읽기]

==================================
파일읽기 권한 관련 클래스

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.security.PrivilegedExceptionAction;

public class PriviegedExceptionAction_I implements PrivilegedExceptionAction{
 public String filePath;
 
 public PriviegedExceptionAction_I(String filePath)
 {
  this.filePath=filePath;
 }
 
    public Object run() throws FileNotFoundException {
        return new FileInputStream(filePath);
    }
 
}

==================================
파일읽기 함수 구현

public byte[] getCertKey(String filePath)
 {
  byte[] baRequesterCert=null;
  try{
   PriviegedExceptionAction_I prv=new PriviegedExceptionAction_I(filePath);
   FileInputStream fis = (FileInputStream) AccessController.doPrivileged(prv);
   int size = fis.available();
   baRequesterCert=new byte[size];
      fis.read(baRequesterCert,0,size);
      fis.close();
  }catch (Exception ex){
   ex.printStackTrace();
  }
  return baRequesterCert;
 }

==================================
파일읽기 함수 호출

byte[] baRequesterCert=getCertKey("C:/JAVAWork/JDCAViewer/cert/signCert.der");



[파일저장]

==================================
파일저장 권한 관련 클래스

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.security.PrivilegedExceptionAction;

public class PriviegedExceptionAction_O implements PrivilegedExceptionAction{
 public String filePath;
 
 public PriviegedExceptionAction_O(String filePath)
 {
  this.filePath=filePath;
 }
 
    public Object run() throws FileNotFoundException {
        FileOutputStream fos=new FileOutputStream(filePath);
        return fos;
    }
}


==================================
파일저장 함수 구현

public void acrFileSave(String filePath,byte[] baARCCertReqMsg)
 {
  
  try{
   PriviegedExceptionAction_O prv=new PriviegedExceptionAction_O(filePath);
   FileOutputStream fos = (FileOutputStream) AccessController.doPrivileged(prv);
   fos.write(baARCCertReqMsg,0,baARCCertReqMsg.length);
   fos.close();
  }catch (Exception ex){
   ex.printStackTrace();
  }
  
 }


==================================
파일저장 함수 호출

acrFileSave(strFilePath+"/2.acq",baARCCertReqMsg);

이렇게 하면 해결됨

AND