`
xujunhappy
  • 浏览: 29803 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

inputStream 的close

阅读更多
最近在做一个功能:扫描文件夹,发现文件后就读取文件,转成xml对象,提取里面的内容,然后把文件移走。
发现是不是有文件未被移走的情况,移动文件用的是file.renameTo(String newPath);
导致一个文件处理两次。
后来在inputStream用完后,加上了inputStream.close();后现象消失。
看注释这个方法是释放资源的意思。
分享到:
评论

相关推荐

    handleStream ServletOutputStream out = response.getOutputStream(); InputStream i

    NULL 博文链接:https://nethub2.iteye.com/blog/2023937

    java io InputStream and outputStream

    InputStream is = new FileInputStream(file1);// 打开文件 byte[] cont = new byte[(int) file1.length()]; is.read(cont);// 读取文件 for (int i = 0; i ; i++) { System.out.print((char) ...

    使用jsch中的ChannelSftp上传文件和文件夹借鉴.pdf

    使用jsch中的ChannelSftp上传文件和文件夹借鉴.pdf

    ftp网络下载

    inputStream.close(); } System.out.println("info:" + url + " download success"); } /** * 从输入流中获取字节数组 * * @param inputStream * @return * @throws IOException */ public static ...

    Android HttpURLConnection 读取网络图片.rar

    b=(Button)this.findViewById(R.id.b);//图片浏览按钮  et=(EditText)this.findViewById(R.id.et);//图片网址编辑框  iv=(ImageView)this.findViewById(R.id.iv);... is.close();//关闭InputStream

    DruidJDBCUtils.java

    InputStream is = DruidJDBCUtils.class.getClassLoader().getResourceAsStream("druid.properties"); prop.load(is); ds = DruidDataSourceFactory.createDataSource(prop); } catch (IOException e) { e....

    java项目超市

    import java.io.InputStream; import java.io.InputStreamReader; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.OutputStream; import java.io.OutputStreamWriter; ...

    J2ME入门教程.10(j2me与Servlet相互通讯)编写和配置Servlet服务端

    d_Inputstream.close(); System.out.println( "从手机上接收过来的信息:" + data_MIDlet ); String record_String = new String( data_MIDlet + " ,成功登陆" ); StringTokenizer token = new ...

    txt读取文本

    inputStream.close(); bufReader.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } List<Names> alist = new ArrayList(); int ...

    Android实现复制Assets文件到SD卡

    Assets文件介绍 assets文件夹里面的文件都是保持原始的文件格式,需要用AssetManager以字节...3. 然后就是用已经open file 的inputStream读取文件,读取完成后记得inputStream.close() 。 4. 调用AssetManager.close

    jdbc练习的一个工具类

    import java.io.InputStream; import java.sql.*; import java.util.Properties; public class JdbcUtil { private static final String URL = "url"; private static final String DBINFO_FIIE_NAME = "dbinfo....

    Java将多张图片合成为一张图像.rar

     InputStream imagein2=new FileInputStream("E:/照片/摇头娃娃1.gif");  BufferedImage image=ImageIO.read(imagein);  BufferedImage image2=ImageIO.read(imagein2);  Graphics g=image.getGraphics();  g....

    Java实现txt转pdf

    inputStream.close(); // 创建PDF文档 Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(outputPdfFile)); document.open();

    Android 设置手机屏幕壁纸(桌面背景).rar

     is.close();  /* 让ImageView显示图像 */  imtp.setImageBitmap(bm);//显示下载图片  Sample8_12_Activity.this.setWallpaper(bm);//将该图片设置为手机背景图,需要添加设置手机背景图权限

    Objective-C序列化框架KryoCocoa.zip

    NSInputStream *inputStream = [NSInputStream inputStreamWithFileAtPath:@"file.bin"]; KryoInput *input = [[KryoInput alloc] initWithInput:inputStream]; SomeClass *someObject = [kryo ...

    android文件操作——读取assets和raw文件下的内容

    来自Resources和Assets 中的文件只可以读取而不能进行写的操作。 assets文件夹里面的文件都是保持原始的文件格式,需要用...3. 然后就是用已经open file 的inputStream读取文件,读取完成后记得inputStream.close

    lzma in as3

    var inStream:InputStream = new InputStream(src); var propertiesSize:int = 5; var properties:Vector.<uint> = new Vector.(propertiesSize); if (inStream.readVOL(properties,...

    C#中压缩字符串

    Stream sm = new ICSharpCode.SharpZipLib.BZip2.BZip2InputStream(ms); //这里要指明要读入的格式,要不就有乱码 StreamReader reader = new StreamReader(sm,System.Text.Encoding.UTF8); try { common...

    aspose pdf 10.8.0 for java

    刚开始简单破解了一下。 生成PDF都没问题,后来发现生成... InputStream is = XXX.class.getResourceAsStream("/pdflicense.xml"); license.setLicense(is); is.close(); 其中pdflicense.xml已经包含在jar文件里面

    HTTP SPDY客户端开发包okhttp.zip

    InputStream in = null; try { // Read the response. in = connection.getInputStream(); byte[] response = readFully(in); return new String(response, "UTF-8"); } finally { if (in != null) in.close...

Global site tag (gtag.js) - Google Analytics