public class homework2 {
public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
Class<?> cls = Class.forName("java.io.File");
Constructor<?>[] constructors = cls.getConstructors();
//遍历输出所有构造器
for (Constructor<?> constructor : constructors) {
System.out.println(constructor);
}
//通过构造器生成文件
Constructor<?> constructor = cls.getConstructor(String.class);
String filePath = "d:\\text.txt";
Object o1 = constructor.newInstance(filePath);
Method createNewFile = cls.getMethod("createNewFile");
createNewFile.invoke(o1);
}
}