Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Selenium-写入网络驱动器。可以写入文本文件,但不能写入图像文件_Java_Webdriver_Javax.imageio_Smb - Fatal编程技术网

Java Selenium-写入网络驱动器。可以写入文本文件,但不能写入图像文件

Java Selenium-写入网络驱动器。可以写入文本文件,但不能写入图像文件,java,webdriver,javax.imageio,smb,Java,Webdriver,Javax.imageio,Smb,我很抱歉,如果这是已经张贴,但似乎有这么多的答案,所以我想我会要求在这里得到一些澄清。我使用以下截图Webdriver代码将截图写入本地驱动器,效果非常好: final Screenshot screenshot = new AShot().shootingStrategy( new ViewportPastingStrategy(500)).takeScreenshot(driver); final BufferedImage image = screenshot.getImage(); F

我很抱歉,如果这是已经张贴,但似乎有这么多的答案,所以我想我会要求在这里得到一些澄清。我使用以下截图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);
这个文件完全可以写入我的本地驱动器。但是,我想写入我有权访问的网络驱动器,并且已经测试了这种访问,因为我能够写入文本文件

驱动器如下所示(使用我的姓名和密码):smb://globalnerds;卡尔·刘易斯:Default32@file-16ca.bs.bview.com/bs-test/

我可以在那里写一个文本文件,但当我试图写图像时,它不起作用

有人能帮我弄清楚吗


谢谢

因此,我想出了如何做到这一点,并使用下面的代码进行了出色的工作。我抓取一个图像并用凭证将其写入共享目录。我正在一行中传递我的凭据和路径:

public void 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:MYBEARPASSWORD@file-6666ca.haq.portview.com/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) {
        }
    }


}

您可能不应该发布您的真实用户名/密码,如果您发布了,请更改它。:-)除此之外,您是否从Java程序编写了一个文本文件?您确定您的Java程序运行时与您的用户具有相同的访问权限吗?谢谢haraldK。这不是真实的用户名或密码。只是为了语法。:。我从Java p是的。如果我用.png重命名文件,它也会写,但会是一个空文件。