所以我想做的是
- 接受用户输入(应该是文件名),并检查该文件是否存在于我当前的工作文件夹中。 (我不需要帮助,这已受到控制)
- 如果文件存在,我想创建该文件的实例。 (我想这样做,以便可以使用反射并检查文件是否为特定接口,并检查构造函数。
因此,为了测试我的程序,我创建了一个现有文件的实例,如下所示:
File tempFile = new File("/CURRENTFOLDER/" + file + ".java");
//with the user input tempFile = Test1.
if(tempFile.exists()){
Test1 test1 = new Test1();
Class<?> test1_class = test1.getclass();
但是我真正想做的是这样的:
File tempFile = new File("CURRENTFOLDER" + file + ".java");
if(tempFile.exists()){
//Test1 test1 = new Test1();
//Class<?> test1_class = test1.getclass();
tempFile instance_of_tempFile = new tempFile();
Class<?> ? test_class = instance_of_tempFile.getclass();
我知道,您不会写tempFile instance_of_tempFile = new tempFile();
,而只写了那封信,这样您就可以理解我的工作。