美文网首页
常用的java片段

常用的java片段

作者: gooch | 来源:发表于2017-10-19 20:07 被阅读0次
  1. 使用NIO进行文件copy
public static void fileCopy( File in, File out )    
            throws IOException    
    {    
        FileChannel inChannel = new FileInputStream( in ).getChannel();    
        FileChannel outChannel = new FileOutputStream( out ).getChannel();    
        try   
        {    
//          inChannel.transferTo(0, inChannel.size(), outChannel);      // original -- apparently has trouble copying large files on Windows    
  
            // magic number for Windows, 64Mb - 32Kb)    
            int maxCount = (64 * 1024 * 1024) - (32 * 1024);    
            long size = inChannel.size();    
            long position = 0;    
            while ( position < size )    
            {    
               position += inChannel.transferTo( position, maxCount, outChannel );    
            }    
        }    
        finally   
        {    
            if ( inChannel != null )    
            {    
               inChannel.close();    
            }    
            if ( outChannel != null )    
            {    
                outChannel.close();    
            }    
        }    
    }  

2、Http代理设置

System.getProperties().put("http.proxyHost", "someProxyURL");    
System.getProperties().put("http.proxyPort", "someProxyPort");    
System.getProperties().put("http.proxyUser", "someUserName");    
System.getProperties().put("http.proxyPassword", "somePassword");  

3、

相关文章

  • 常用的java片段

    使用NIO进行文件copy 2、Http代理设置 3、

  • Groovy补充

    Java中运行Groovy,有三种比较常用的类支持 GroovyShell通常用来运行"script片段"或者一些...

  • PHPStorm快捷键1

    常用代码片段 CTRL + j能够快捷的输入常用的代码片段,类似vim的 snipMate,可以自定义代码片段 类...

  • JDBC连接Oracle数据库简单步骤

    @(Java)代码片段

  • Vue3 常用代码片段

    1、 Vue3 常用代码片段 snippets: 日常开发中常用的代码片段及组件封装集合[https://gith...

  • Android中的TextView实现文字变色

    方法一:xml代码片段: Java代码片段: 效果图如下:方法二:用SpannableString来实现。Java...

  • Python的常用片段

    1.判断对象类型(type()函数) 判断基本数据类型可以直接写int,str等,但如果要判断一个对象是否是函数怎...

  • rails中的cache

    缓存指南总结 Web 应用中常用的各种 Cache 最常用的cache应该是页面的片段缓存和底层缓存。 片段缓存A...

  • 蓝牙发送数据和接收数据

    蓝牙通信代码片段记录 OpenBleHelper.java HexDump.java

  • JavaSE Day19 IO

    1. Java 中常用的 I/O 流常用类型在哪个包?常用类型有哪些? I/O 流的常用类型都在 java.io ...

网友评论

      本文标题:常用的java片段

      本文链接:https://www.haomeiwen.com/subject/mhypuxtx.html