从OutputStream创建文件

Pab*_*rit 5 java outputstream fileoutputstream

我有一个正在创建文件的问题,但是这正在创建空文件。

我正在使用Dropbox的API,Dropbox的代码运行良好,但是我不知道我没有问题。我已经为我的应用程序使用了2º和3º代码,这运行良好。

这按层次操作。我正在发送outputStream功能。但这是空的。

我正在使用outputStream,因为我需要它与outputstream一起运行。

1º代码(Class Test || Call):

File tempFile=new File("C:\\PRUEBAS_TFG\\cloud.png"); if ( ! tempFile.exists() ) { tempFile.createNewFile(); } 
File file = new File("C:\\PRUEBAS_TFG\\cloud.png");
OutputStream outputStream = new FileOutputStream(file);
catmanager.downloadFilesToItem(catmanager.getAllListCatalog().get(0), catmanager.getAllListCatalog().get(0).getItems().get(2), listFile, outputStream);
outputStream.close();
Run Code Online (Sandbox Code Playgroud)

2º代码(类别管理员||1ºbody):

public void downloadFilesToItem(Catalog catalog, Item item, List<String> files, OutputStream output){
    try{
        String fsPath;
        fsPath = pathCatalog(catalog);
        getFSManager().changeDirectoryConfigNPath(fsPath+"/"+item.getName()+"_item");
        for(int i = 0;i<files.size();i++){
            getFSManager().downloadFile(files.get(i), output);
        }
    }catch(Exception e){
        e.printStackTrace();
    }
}
Run Code Online (Sandbox Code Playgroud)

3ºCode(FSManager类||2ºbody)

public void downloadFile(String fileName, OutputStream output) throws IOException{//Aqui deveria Buscar el Fichero Funciona por que da la casualidad que esta el fichero en la primera nube 
    /** Cogemos la lista de FS del usuario */
    List<IFileSystem> aux = getFileSystemsUser();

    for(int i = 0; i < aux.size();i++){
        /** Se realiza la Funcionalidad del metodo*/
        System.out.println(aux.get(i).toString());
        try{
            aux.get(i).downloadFile(_listPath.get(i)+"/"+fileName, output);
            i = aux.size()+1;
        }catch(IOException e) {

        }
    }
}
Run Code Online (Sandbox Code Playgroud)

4ºCode(Class aux Dropbox || API Dropbox):

public void downloadFile(String fileName, OutputStream aux) throws IOException{
    try{
        getDbxClient().getFile(fileName, null, aux);
    }catch(IOException e){
        throw e;
    }catch(DbxException u){
        throw new IOException(u.getCause());
    }
}
Run Code Online (Sandbox Code Playgroud)

感谢前进。

小智 0

我想你必须flush(参见相应的方法)将输出流添加到你的文件中(并关闭它)。Dropbox API 正在处理 OutputStream,但肯定不关心您要写入文件。

你可以看看下面的例子