可以这样搞,
File file = new File("目录路径");
File[] files = file.list();
for(String f : files) {
   if(f.isFile()) {
        FileInputStream fis = new FileInputStream("目录路径"+fileName);
        //再做你想做的
    }
    if(f.isDirectory()) {
        //再处理
    }
}

解决方案 »

  1.   

    这样写入到一个文件不是也存到本地了吗  关键我只需要一个输入流   其实我是用smack来发送文件夹的发送文件需要一个inputstraem  就是这样  不知道怎么把没一个文件读取到  放入到一个输入流中
      

  2.   

    以下是一个简单的递归的读取文件夹下的文件方法
    public class ReadFile {
    public static boolean rdFile(String filePath){
    File file = new File(filePath);
    if(!file.isDirectory()){
    System.out.println("文件名:"+file.getName());
    }else if(file.isDirectory()){
    String[] list = file.list();
    for(int i =0;i<list.length;i++){
    File files = new File(filePath+"\\"+list[i]);
    if(!files.isDirectory()){
    System.out.println("文件名:"+files.getName());
    }else if(files.isDirectory()){
    rdFile(filePath+"\\"+list[i]);
    }
    }
    }
    return true;
    }
      

  3.   

    public Boolean readAllFile(String path) { File file = new File(path); if (!file.exists()) {
    return false;
    }
    // 这个路径就是一个文件
    if (file.isFile()) {

    return true;
    } File[] fileList = file.listFiles();
    for (int i = 0; i < fileList.length; i++) {
    if (fileList[i].isDirectory()) {
    readFile(oldPath + fileList[i].separator + fileList[i].getName());
    } else {
    encryotFile(oldPath + fileList[i].separator + fileList[i].getName());
    }
    }
    return true;
    }
    public void readFile(String filePath) {                         File file = new File(filePath);
                             byte[] buffer = null;
    FileOutputStream outputStream = null;
    InputStream inputStream = null;
    int lenBuffer = 0;try{
    if (file.isFile() && file.exists()) {
    inputStream = new FileInputStream(file);
    BufferedInputStream reader = new BufferedInputStream(inputStream); lenBuffer = inputStream.available();
    buffer = new byte[lenBuffer];
    reader.read(buffer, 0, lenBuffer);
    inputStream.close();

    reader.close();
    } } catch (FileNotFoundException e) {
    e.printStackTrace();
    } catch (Exception e) {
    e.printStackTrace();
    }}