下列程序的功能是显示用户在命令行方式下指定的任意驱动器目录,请补充程序。
import java.iO.*;
public class FindDirectories
public static void main (String args[ ])
if(args.length= =0)
args=new String[ ]"..";
try
File pathName=new File(args [0]);
String[]fileName=pathName.list( );
for(int i=0;<fileName.length;i+ +)
File f=new 【15】
if(f.isDirectory( ))
System.out.println(f.getCanonicalPath( ));
main(new String[ ]
f.getPath( )
);
catch(IOException e)
e.printStackTrace( );
参考答案:【15】File(pathName.getPath( ),fileName[i])
解析:解析:有以下两个语句都可以创建一个文件,其中构造方法的参数,可以是路径文件名,也可以是路径和文件名。
File Pathname = new File(arge[O]);//路径文件名来建立文件对象
File f=new File (pathname.getPath,fileName[i]);//(路径,文件名)
本题中,采用第二种方法来创建文件。