サーバーとして機能する をSSH
使用して、チャネル経由でテキスト ファイルを読み取ることができました。私の質問は、画像ファイルを送信して、のようなアプリケーションで表示するにはどうすればよいですか? 私はそれをするのに問題があるようです。Ubuntu
Linux
SSH
JPanel
以下は、このフォーラムからのもので、私が使用したコードです。ユーザーワールドへのクレジット
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 the
JPanel` はできます。
それは私に次の例外を与えます
Establishing connection
Connection Established
Creating SFTP Channel.
SFTP Channel Established
javax.imageio.IIOException: Can't read input file!
ただし、ファイルパスを数え切れないほどチェックしました。正しいです。私のコードの何が問題なのかを知ることができますか?