1

我已经设法通过使用作为服务器的SSH通道读取文本文件。我的问题是如何发送图像文件并将其显示在应用程序中,例如?我这样做似乎有问题。Ubuntu LinuxSSHJPanel

下面是我使用的来自这个论坛的代码。致用户世界的学分

public static void main(String []args) throws Exception
{

    String user="larry";
    String password="123";
    String host="192.168.174.131";
    int port = 22;
    String remoteFile="/home/larry/seohyun.jpg";



    try
    {
        JSch jsch=new JSch();
        Session session=jsch.getSession(user,host,port);
        session.setPassword(password);
        session.setConfig("StrictHostKeyChecking","no");
        System.out.println("Establishing connection");
        session.connect();

        System.out.println("Connection Established");
        System.out.println("Creating SFTP Channel.");
        ChannelSftp sftpChannel=(ChannelSftp) session.openChannel("sftp");
        sftpChannel.connect();
        System.out.println("SFTP Channel Established");

        InputStream out=null;
        out=sftpChannel.get(remoteFile);
        BufferedReader br=new BufferedReader(new InputStreamReader(out));

        String imageName = br.readLine();
        File input = new File(imageName);
        image = ImageIO.read(input);


        JFrame frame = new JFrame("Display Image");
        Panel panel = new TestSSH();
        frame.getContentPane().add(panel);
        frame.setSize(500,500);
        frame.setVisible(true);




    }catch(Exception e)
    {
        System.err.print(e);
    }

}

但是我可以t seem to be able to display the image on theJPanel`。

它给了我以下异常

Establishing connection
Connection Established
Creating SFTP Channel.
SFTP Channel Established
javax.imageio.IIOException: Can't read input file!

但是,我已经无数次检查了文件路径。它是正确的。我可以知道我的代码有什么问题吗?

4

0 回答 0