[英]File loading using getClass().getResource(“…”).getFile()
first topic on stackoverflow, been using it for years, but can't find a solution to this: I need to fill a JTable with names of files in a directory (using Eclipse IDE). 关于stackoverflow的第一个主题已经使用了很多年,但是对此却找不到解决方案:我需要用目录中文件的名称填充JTable(使用Eclipse IDE)。
im using this: 即时通讯使用此:
public void getFilesName()
{
File dir = new File(getClass().getResource("C:\\Files\\Server\\").getFile());
File[] files = dir.listFiles();
modelo.setColumnIdentifiers(new String[]{"Files Names"});
Object[] row = new Object[1];
for(int i = 0; i < files.length; i++)
{
row[0] = files[i].getName();
modelo.addRow(row);
}
}
but it returns: 但它返回:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
and I can't find a way to do it. 而且我找不到办法。
Try to use: 尝试使用:
File dir = new File("C:\\Files\\Server\\");
File[] files = dir.listFiles();
Instead of: 代替:
File dir = new File(getClass().getResource("C:\\Files\\Server\\").getFile());
File[] files = dir.listFiles();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.