main函数中args[0]中是一个.txt的文件名,请问这个文件存在什么路径下才能输出这个txt文件呢?程序如下:
importjava.io.*;classShowFile{publicstaticvoidmain(Stringargs[]){inti;FileInputStream...
import java.io.*;
class ShowFile {
public static void main(String args[])
{
int i;
FileInputStream fin;
// First make sure that a file has been specified.
if(args.length != 1) {
System.out.println("Usage: ShowFile File");
return;
}
try {
fin = new FileInputStream(args[0]);
} catch(FileNotFoundException exc) {
System.out.println("File Not Found");
return;
}
try {
// read bytes until EOF is encountered
do {
i = fin.read();
if(i != -1) System.out.print((char) i);
} while(i != -1);
} catch(IOException exc) {
System.out.println("Error reading file.");
}
try {
fin.close();
} catch(IOException exc) {
System.out.println("Error closing file.");
}
}
} 展开
class ShowFile {
public static void main(String args[])
{
int i;
FileInputStream fin;
// First make sure that a file has been specified.
if(args.length != 1) {
System.out.println("Usage: ShowFile File");
return;
}
try {
fin = new FileInputStream(args[0]);
} catch(FileNotFoundException exc) {
System.out.println("File Not Found");
return;
}
try {
// read bytes until EOF is encountered
do {
i = fin.read();
if(i != -1) System.out.print((char) i);
} while(i != -1);
} catch(IOException exc) {
System.out.println("Error reading file.");
}
try {
fin.close();
} catch(IOException exc) {
System.out.println("Error closing file.");
}
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询