java 如何读取文件夹中文件

来源:百度知道 编辑:UC知道 时间:2024/06/05 16:31:30
还希望能判别文件夹中是否有新的.JPG文件 追加分数

package sample;
import java.io.*;
public class CopyFileStream{ // copy one file to another file
public static void main(String args[]) {
FileInputStream fromFile=null;
FileOutputStream toFile=null;
try{
//生成两个已有byte文件的 流对象。
fromFile=new FileInputStream(args[0]); // get file name from console
toFile=new FileOutputStream(args[1]); // get file name from console
} catch (FileNotFoundException e){
System.err.println("File could not be found");
return; //缺文件名输入,抛异常,返回。
} catch (IOException e){
System.err.println("File could not be copied ");
return;
} catch (ArrayIndexOutOfBoundsException e){
System.err.println("Usage: CopyByteFile from-file to-file");
return;
}
try {
fromFile.close(); // close InputStr