나는 동시에 실행되도록 설계된 두 가지 응용 프로그램을 만들었습니다. (나는 그것들을 결합하고 싶지 않습니다.) 하나는 특정 파일에서 읽고 다른 하나는이 파일에 쓰기를했습니다. 어느 쪽이든 다른 쪽이 에러를 실행하지 않는 경우, 양쪽 모두가 get를 실행하고있는 경우, 액세스는 거부 된 에러가됩니다. 최초의 관련 코드 : 두 번째의JAVA : 두 앱이 어떻게 같은 파일에 액세스 할 수 있습니까?
class MakeImage implements Runnable {
@Override
public void run() {
File file = new File("C:/Users/jeremy/Desktop/New folder (3)/test.png");
while (true) {
try{
//make image
if(image!=null)
{
file.createNewFile();
ImageIO.write(image, "png", file);
hello.repaint();}}
catch(Exception e)
{
e.printStackTrace();
}
}
}
}
관련 코드 :
BufferedImage image = null;
try {
// Read from a file
image = ImageIO.read(new File("C:/Users/jeremy/Desktop/New folder (3)/test.png"));
}
catch(Exception e){
e.printStackTrace();
}
if(image!=null)
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(image, "png", baos);
baos.flush();
byte[] imageInByte = baos.toByteArray();
baos.close();
returns=Base64.encodeBase64String(imageInByte);
}
내가이 바라 보았다 : Java: how to handle two process trying to modify the same file하지만, 모두가 하나가 여기에 파일을 writting되는 때입니다. 행운을 빌리지 않고 이전 답변에서 제안한대로 재시도 방법을 시도했습니다. 어떤 도움이라도 대단히 감사하겠습니다.
데이터베이스 엔진? – Randy
쓰기시 복사 ?? – Joel