java文件在通常情况下是不显示java图标的,这个跟你安装的开发工具有关,像安装jbuilder后,java文件就显示成java图标,而eclipse就不显示,.java本身就是个文本文件而已。
第一首先在电脑上下载好java的编程软件。
然后在点击打开命令框。
2
第二然后在计算机上右键打开属性。
在属性对话框上点击高级。
3
第三然后再点击下面的环境变量。
4
第四然后在环境变量的窗口下面的系统变量中。
点击选中path。
5
第五然后再点击编辑。
再点击新建,将下载好的java编程软件的保存路径添加到上面,在点击确定。
注意:不要随意删除path中的东西。
6
第六然后在命令框窗口中输入java。
再按回车键,要是会出现一大堆命令,说明java的运行环境弄好。
java可使用FileSystemView和ShellFolder类获取文件的小图标和大图标,以下是详细代码:
import java.awt.FlowLayoutimport java.io.File
import java.io.FileNotFoundException
import javax.swing.Icon
import javax.swing.ImageIcon
import javax.swing.JFrame
import javax.swing.JLabel
import javax.swing.filechooser.FileSystemView
public class GetFileIcon {
/**
* @param args
*/
public static void main( String[] args )
{
String filePath = "D:/sheet1.xlsx"
File f = new File( filePath )
JFrame frm = new JFrame()
frm.setSize( 300, 200 )
frm.setLocationRelativeTo( null )
frm.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE )
frm.setVisible( true )
frm.setLayout( new FlowLayout( 10, 10, FlowLayout.LEADING ) )
JLabel sl = new JLabel( "小图标" )
frm.add( sl )
JLabel bl = new JLabel( "大图标" )
frm.add( bl )
sl.setIcon( getSmallIcon( f ) )
bl.setIcon( getBigIcon( f ) )
}
/**
* 获取小图标
* @param f
* @return
*/
private static Icon getSmallIcon( File f )
{
if ( f != null && f.exists() )
{
FileSystemView fsv = FileSystemView.getFileSystemView()
return(fsv.getSystemIcon( f ) )
}
return(null)
}
/**
* 获取大图标
* @param f
* @return
*/
private static Icon getBigIcon( File f )
{
if ( f != null && f.exists() )
{
try {
sun.awt.shell.ShellFolder sf = sun.awt.shell.ShellFolder.getShellFolder( f )
return(new ImageIcon( sf.getIcon( true ) ) )
} catch ( FileNotFoundException e ) {
/* TODO Auto-generated catch block */
e.printStackTrace()
}
}
return(null)
}
}