我是Java编程的初学者,我现在需要一个非常重要的项目。我在php中制作了一个基于web的用户界面,现在我需要将Java程序集成到php上以在后端运行。但在此之前,我遇到了以下问题:
-
java程序只能读取特定的文件。
oImage = new FileInputStream(new File("<image path>"));
-
是否有任何方法,我可以通过一个变量包含从PHP文件到Java程序的图像路径?
您可以简单地编写一个公共静态void main函数并读取控制台输入(来自PHP) -只需将图像路径作为参数传递,您就完成了
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import javax.imageio.ImageIO;
public class OurPaint {
private BufferedImage paint;
private int x = 5;
private int y = 320;
public OurPaint() {
try {
paint = ImageIO.read(new URL("path"));
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public BufferedImage getPaint() {
return paint;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
}
这将从url加载图像,您也可以使用文件阅读器。