1

イメージをリモートの場所に保存しようとしています。

BufferedImage img;
img=ImageIO.read(file);
String url="http://localhost:8080/prashant Pic/j.jpg";
ImageIO.write(img, "jpg",new File("/home/com/Documents/images/p.jpg"));
ImageIO.write(img, "jpg",new File("http://localhost:8080/prashant Pic/j.jpg"));

イメージをローカル コンピューターに保存します。しかし、ローカルホストにはありません。

4

1 に答える 1

0

離れた場所に画像を保存することは完全に可能です。を使用する代わりに、次のFileようなものを使用します。

URL url = new URL("http://localhost:8080/prashant%20Pic/j.jpg");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);

// Do necessary setup of connection, like:
//  - setting the HTTP method (POST/PUT)
//  - setting authentication parameters?
// These depends on what kind of service you have running on localhost:8080

OutputStream stream = connection.getOutputStream();
try {
    ImageIO.write(img, "jpg", stream);
}
finally {
    stream.close();
}

もちろん、localhost:8080 で実行され、POST または PUT によるファイルのアップロードを受け入れるサービスも必要です。

于 2013-07-16T07:54:39.390 に答える