package imageio;
import javax.imageio.*;//for ImageIO.read
import java.awt.image.BufferedImage;
import java.awt.*;//for JFrame and JLabel etc
import javax.swing.*;//for JFrame and JLabel etc
import java.net.*;//for URL
import java.io.*;//for catch (IOException e),File,InputStream, BufferedInputStream,and FileInputStream ect
public class Example {
public static void main (String[] args){
String dir = System.getProperty("user.dir");//获得当前路径
System.out.println(dir);
File f = new File(".");//获得当前文件路径
String absolutePath = f.getAbsolutePath();
System.out.println(absolutePath);
Image image = null;
try {
// Read from a file
File sourceimage = new File(".\\pic\\over.gif"); //source.gif图片要与HelloJava.java同在一目录下
image = ImageIO.read(sourceimage);
// Read from an input stream
//InputStream is = new BufferedInputStream(
// new FileInputStream(".\\pic\\over.gif")); //mid.jpg图片要与HelloJava.java同在一目录下
// image = ImageIO.read(is);
// Read from a URL
//URL url = new URL("http://www.javaworld.com/images/012407-tipsbox.jpg");
// image = ImageIO.read(url);
} catch (IOException e) {
}
// Use a label to display the image
JFrame frame = new JFrame();
JLabel label = new JLabel(new ImageIcon(image));
frame.getContentPane().add(label, BorderLayout.CENTER);
frame.pack();
frame.setVisible(true);
//关闭窗口--退出调试
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
import javax.imageio.*;//for ImageIO.read
import java.awt.image.BufferedImage;
import java.awt.*;//for JFrame and JLabel etc
import javax.swing.*;//for JFrame and JLabel etc
import java.net.*;//for URL
import java.io.*;//for catch (IOException e),File,InputStream, BufferedInputStream,and FileInputStream ect
public class Example {
public static void main (String[] args){
String dir = System.getProperty("user.dir");//获得当前路径
System.out.println(dir);
File f = new File(".");//获得当前文件路径
String absolutePath = f.getAbsolutePath();
System.out.println(absolutePath);
Image image = null;
try {
// Read from a file
File sourceimage = new File(".\\pic\\over.gif"); //source.gif图片要与HelloJava.java同在一目录下
image = ImageIO.read(sourceimage);
// Read from an input stream
//InputStream is = new BufferedInputStream(
// new FileInputStream(".\\pic\\over.gif")); //mid.jpg图片要与HelloJava.java同在一目录下
// image = ImageIO.read(is);
// Read from a URL
//URL url = new URL("http://www.javaworld.com/images/012407-tipsbox.jpg");
// image = ImageIO.read(url);
} catch (IOException e) {
}
// Use a label to display the image
JFrame frame = new JFrame();
JLabel label = new JLabel(new ImageIcon(image));
frame.getContentPane().add(label, BorderLayout.CENTER);
frame.pack();
frame.setVisible(true);
//关闭窗口--退出调试
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
本文使用Blog_Backup未注册版本导出,请到soft.pt42.com注册。