java怎么根据二进制文件流映射到File 呢? processImportData(final File file)后台方法的参数 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 那你可以把byte[] 写入一个文件,然后new File吧 processImportData(final File file)这个设计接口有问题啊,为什么不是processImportData(final InputStream inputStream)不生成临时文件没办法传参 我在网上看到一个通过二进制流新建文件的方法,但是用起来感觉有问题,文件可以生成,但是用完之后文件显示是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); FileOutputStream fstream ,这个应该也的关闭 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; } 你写的这个与我上面贴的代码没有上面不一样啊File file = getFileFromBytes...只能这样传了 求:一段js将map转成String request.getParameter()的问题 JSP里图片路径到底要怎么表示?!file not found! 新手 我只学过think in java能搞WEB开发么??? 求树型结构!!急! 又一个简单的问题 又一个得分的问题 关于数据库查询语句字符串匹配的问题 在weblogic6.1里,在一个域下配置多个server,使每个server都running 交互虚拟网站建设 防止程序外表单提交 MyEclipse经过设置后新建文件编码问题 js 正则表达式 文本框 匹配 aaaa/bs/cd
这个设计接口有问题啊,为什么不是
processImportData(final InputStream inputStream)不生成临时文件没办法传参
我在网上看到一个通过二进制流新建文件的方法,但是用起来感觉有问题,文件可以生成,但是用完之后文件显示是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);
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;
}