processImportData(final File file)后台方法的参数

解决方案 »

  1.   

    那你可以把byte[] 写入一个文件,然后new File吧
      

  2.   

    processImportData(final File file)
    这个设计接口有问题啊,为什么不是
    processImportData(final InputStream inputStream)不生成临时文件没办法传参
      

  3.   


    我在网上看到一个通过二进制流新建文件的方法,但是用起来感觉有问题,文件可以生成,但是用完之后文件显示是0k,本来想打开看的,又提示我有进程在使用,不过文件里面的数据已经被我读取到java临时变量了,数据是对的,网上的代码片如下:/**
         * 把文件流保存成物理文件
         * @param content
         * @param outputFile
         * @return
         */
        private File getFileFromBytes(final byte[] content, final String outputFile)
        {
            BufferedOutputStream stream = null;
            File file = null;
            try
            {
                file = new File(outputFile);
                final FileOutputStream fstream = new FileOutputStream(file);
                stream = new BufferedOutputStream(fstream);
                stream.write(content);//调试到这里文件已经生成
            }
            catch (final Exception e)
            {
                e.printStackTrace();
            }
            finally
            {
                if (stream != null)
                {
                    try
                    {
                        stream.close();
                    }
                    catch (final IOException e)
                    {
                        e.printStackTrace();
                    }
                }
            }
            return file;
        }我是在一个方法里面这么用的
     File file = getFileFromBytes(content, filepath);
      

  4.   

    FileOutputStream fstream ,这个应该也的关闭
      

  5.   

    public static File getFileFromBytes(byte[] b, String outputFile) ...{
            BufferedOutputStream stream = null;
            File file = null;
            try ...{
                file = new File(outputFile);
                FileOutputStream fstream = new FileOutputStream(file);
                stream = new BufferedOutputStream(fstream);
                stream.write(b);
            } catch (Exception e) ...{
                e.printStackTrace();
            } finally ...{
                if (stream != null) ...{
                    try ...{
                        stream.close();
                    } catch (IOException e1) ...{
                        e1.printStackTrace();
                    }
                }
            }
            return file;
        }
      

  6.   

    你写的这个与我上面贴的代码没有上面不一样啊File file = getFileFromBytes...只能这样传了