2017-09-20 3 views
0

이 글이 이미 게시되었지만 너무 많은 답변이있는 것 같아서 죄송합니다. 그래서 여기에 몇 가지 설명을달라고 요청했습니다. 임 내 로컬 드라이브에 스크린 샷을 작성하는 다음 스크린 샷 Webdriver 코드를 사용하고 잘 작동 :셀레늄 - 네트워크 드라이브에 쓰기. 텍스트 파일을 쓸 수는 있지만 이미지 파일은 쓸 수 없습니다

final Screenshot screenshot = new AShot().shootingStrategy(
new ViewportPastingStrategy(500)).takeScreenshot(driver); 
final BufferedImage image = screenshot.getImage(); 

File outputfile = new File("//Users/me/Desktop/testfolder/saved.png"); 
ImageIO.write(image, "PNG", outputfile); 

이 파일은 내 로컬 드라이브에 완벽하게 작성합니다. 그러나 액세스 권한이있는 네트워크 드라이브에 쓰기를 원하고 텍스트 파일을 쓸 수 있으므로이 액세스를 테스트했습니다. // globalnerds, Carl.Lewis : SMB :

드라이브 (내 이름과 암호를 사용하여) 다음과 같습니다 [email protected]/bs-test/

내가 쓸 수 있습니다 텍스트 파일이 있지만 이미지를 쓰려고 할 때 작동하지 않습니다.

아무도 나를 알아낼 수 있습니까?

감사합니다.

+0

가 발생합니다. :-) 그 외, 자바 프로그램에서 텍스트 파일을 작성 했습니까? Java 프로그램이 사용자와 동일한 액세스 권한으로 실행되고 있습니까? – haraldK

+1

감사합니다 haraldK. 이것은 실제 사용자 이름 또는 암호가 아닙니다. 그것은 단지 구문입니다. :). 나는 자바 프로그램 YES에서 텍스트 파일을 썼다. 파일의 이름을 .png로 변경하면 쓰기도되지만 빈 파일이됩니다. –

답변

0

그래서 어떻게하는지 알아 냈고 아래 코드를 사용하여 매력처럼 작동했습니다. 이미지를 가져 와서 자격 증명이있는 공유 디렉토리에 씁니다. 내가 한 줄에 내 자격 증명과 경로를 통과 해요 :

공공 무효 WriteMe을() 당신은 아마 당신이 한 경우, 변경, 당신의 진짜 이름/암호를 게시해서는 안 예외 {

InputStream in = null; 
    OutputStream out = null; 
    try { 
     //Get a picture 
     File localFile = new File ("//Users/BIG.BEAR/Desktop/testfolder/saved.png"); 
     String remotePhotoUrl = "smb://globalnerds;BIG.BEAR:[email protected]/testfolder/"; //The shared directory to store pictures 
     SimpleDateFormat fmt = new SimpleDateFormat ("yyyyMMddHHmmssSSS_"); 
     SmbFile remoteFile = new SmbFile (remotePhotoUrl + "/" + fmt.format (new Date()) + localFile.getName()); 
     remoteFile.connect(); //Try to connect 

     in = new BufferedInputStream (new FileInputStream (localFile)); 
     out = new BufferedOutputStream (new SmbFileOutputStream (remoteFile)); 

     byte[] buffer = new byte[4096]; 
     int len = 0; //Read length 
     while ((len = in.read (buffer, 0, buffer.length)) != -1) { 
      out.write (buffer, 0, len); 
     } 
     out.flush(); //The refresh buffer output stream 
    } catch (Exception e) { 
     String msg = "The error occurred: " + e.getLocalizedMessage(); 
     System.out.println (msg); 
    } finally { 
     try { 
      if (out != null) { 
       out.close(); 
      } 
      if (in != null) { 
       in.close(); 
      } 
     } catch (Exception e) { 
     } 
    } 


} 
관련 문제