DataOutputStream AllData = new DataOutputStream(new FileOutputStream(filename_date + ".bin"));
怎么把这个生成的文件放到SD卡自己指定的文件夹下面呢?
比如:
   这个文件生成在Android文件夹---->Data文件夹----->应用文件夹---->filename_date.bin;
我让它放到
    SD目录下----->我指定文件夹(如:Test文件夹)----->filename_date.bin这个怎么实现呢? 
刚开始学习Android!谢谢了!!

解决方案 »

  1.   

    public InputStream getInputStream(String path) throws FileNotFoundException{
    FileInputStream filein = null;
    filein = new FileInputStream(new File(path));
    BufferedInputStream in = null;
    if(filein != null)
    in = new BufferedInputStream(filein);
    return in;
    }/**
     * 把输入流中的数据输入到Path里的文件里
     * @param path
     * @param fileName
     * @param inputStream
     * @return
     */
    public File writeFromInputToSD(String path,InputStream inputStream){
    File file = null;
    OutputStream output = null;
    try{
    file = new File(path);
    output = new FileOutputStream(file);
    byte[] buffer = new byte[4*1024];
    int temp;
    while((temp=inputStream.read(buffer))!=-1){
    output.write(buffer,0,temp);
    }
    output.flush();
    }catch(Exception e){
    e.printStackTrace();
    }finally{
    try{
    output.close();
    }catch(Exception e){
    e.printStackTrace();
    }
    }
    return file;
    }实现的时候调用就行
    String source = "......";
    String to = "/SD/test/filename_date.bin";writeFromInputToSD(to,getInputStream(source));希望对你有帮助啦自己去尝试吧
      

  2.   

    大哥,Android的,我这里能生成文件,生成的文件都放到默认的文件夹中的,我想放入指定的文件夹,这才是重点,这才是我要求的,这才是我所要的~!
      

  3.   

    你不是能生成文件么File file = new File("你的sd卡+文件路径");
    DataOutputStream AllData = new DataOutputStream(new FileOutputStream(file));
     
    不就行了?
      

  4.   

    /**
     * 
     * @param path传入路径字符串
     * @return File
     */
    public File creatFileIfNotExist(String path){
    File file = new File(path);
    if(!file.exists()){
      try {   
                      new File(path.substring(0, path.lastIndexOf(File.separator))).mkdirs();
                      file.createNewFile();
                      Log.i("creatFileIfNotExits", "Path:"+path+"creat success");
      } catch (IOException e) {
                      e.printStackTrace();
                     Log.i("creatFileIfNotExits","Path:"+path+"&"+e.getMessage());
      }
    }
    return file;
    }
    难道不能生成文件嘛,我这样子可是能在任何地方生成 文件的。