使用spring-mvc框架时,jetty找不到spring.tld和spring-form.tld 只能把s […]
读取Java文件到byte数组的三种方式
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
import java.io.BufferedInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.RandomAccessFile; import java.nio.ByteBuffer; import java.nio.MappedByteBuffer; import java.nio.channels.FileChannel; import java.nio.channels.FileChannel.MapMode; public class FileUtils { /** * the traditional io way * @param filename * @return * @throws IOException */ public static byte[] toByteArray(String filename) throws IOException{ File f = new File(filename); if(!f.exists()){ throw new FileNotFoundException(filename); } ByteArrayOutputStream bos = new ByteArrayOutputStream((int)f.length()); BufferedInputStream in = null; try{ in = new BufferedInputStream(new FileInputStream(f)); int buf_size = 1024; byte[] buffer = new byte[buf_size]; int len = 0; while(-1 != (len = in.read(buffer,0,buf_size))){ bos.write(buffer,0,len); } return bos.toByteArray(); }catch (IOException e) { e.printStackTrace(); throw e; }finally{ try{ in.close(); }catch (IOException e) { e.printStackTrace(); } bos.close(); } } /** * NIO way * @param filename * @return * @throws IOException */ public static byte[] toByteArray2(String filename)throws IOException{ File f = new File(filename); if(!f.exists()){ throw new FileNotFoundException(filename); } FileChannel channel = null; FileInputStream fs = null; try{ fs = new FileInputStream(f); channel = fs.getChannel(); ByteBuffer byteBuffer = ByteBuffer.allocate((int)channel.size()); while((channel.read(byteBuffer)) > 0){ // do nothing // System.out.println("reading"); } return byteBuffer.array(); }catch (IOException e) { e.printStackTrace(); throw e; }finally{ try{ channel.close(); }catch (IOException e) { e.printStackTrace(); } try{ fs.close(); }catch (IOException e) { e.printStackTrace(); } } } /** * Mapped File way * MappedByteBuffer 可以在处理大文件时,提升性能 * @param filename * @return * @throws IOException */ public static byte[] toByteArray3(String filename)throws IOException{ FileChannel fc = null; try{ fc = new RandomAccessFile(filename,"r").getChannel(); MappedByteBuffer byteBuffer = fc.map(MapMode.READ_ONLY, 0, fc.size()).load(); System.out.println(byteBuffer.isLoaded()); byte[] result = new byte[(int)fc.size()]; if (byteBuffer.remaining() > 0) { // System.out.println("remain"); byteBuffer.get(result, 0, byteBuffer.remaining()); } return result; }catch (IOException e) { e.printStackTrace(); throw e; }finally{ try{ fc.close(); }catch (IOException e) { e.printStackTrace(); } } } } |
ThinkPHP的Url链接美化
例如你的原路径是 http://localhost/test/index.php/index/add 那么现在 […]
Yii2前后台启用UrlManager以及.htaccess的设置方法
下载了Yii2 Advanced之后,启动一看,发现其默认是不启用UrlManager的。Url还是Get式的 […]
Yii2路径优化隐藏index.php
1.开启apache-rewrite LoadModule rewrite_module modules/mo […]
采用composer安装yii2
1.将php.exe加入环境变量path 2.下载composer https://getcomposer.o […]
spring发行包说明
各发行包的大致描述如下: org.springframework.asm-3.0.0.M4.jar: 提供对A […]
arcgis server 动态创建地图服务代码
加入地图包括图层渲染,标注等,数据从ArcSDE中读出! 代码中有两个数据表:mapinfo(存储地图信息,k […]
ArcGIS Server操作Mxd文件详细讲解
Server发布地图都是基于Mxd去发布的,这点与IMS使用axl文件差不多。一般来说,发布后mxd尽可能不要 […]
XDocument输出
使用XDocument时,用普通的ToString方式无法输出声明,可以按如下方式输出声明 [crayon-6 […]
Android 和iOS 比较之我见
Android和iOS那个好?应该先往哪个上面投入资源?多次被人问到此类问题,笔者刚好自己的项目也需要考虑iO […]
IE中打开UTF-8编码网页显示空白问题
很久很久以前(大概2005年10月~2006年3月),当时在blogger.com写Blog。当时blogge […]
Jbuild7+weblogic6.x配置方法如下:
Win 2000 Temp、Tmp 的配置 因为我们生成的 ejb 相关代码要进行一系列的编译,那么所生成的临 […]
Java时间处理
1:) 字符串转换成时间
1 2 3 4 5 6 7 8 9 10 11 12 13 |
SimpleDateFormat formatter = new SimpleDateFormat ('yyyy.MM.dd'); //假定像2002.07.04的是合法日期其他都非法。 String str='2002.07.04'; ParsePosition pos = new ParsePosition(0); Date dt=formatter.parse(str,pos); if(dt!=null) { //是合法日期 } else { //非法日期 } |
2:)两个日期相减 […]
解决java中文问题
针对applet和awt: 1:) Font f = new Font(UIResource.getStrin […]
array_map函数在PHP类中调用内部方法
在PHP编程中,我们经常会遇到处理数组的单元数据问题,比如对数组中每个单元应用自定义函数。 一种方法是通过循环 […]
WordPress浏览页增加删除日志的链接
I recently had a client ask for a delete post link, lik […]
WordPress导出的WXR文件分割
1,C#方法 2,Python方法 <pre class=”brush:py”& […]
wordpress数据库清理优化
在使用wordpress的时候,新手往往不会关注数据库,但是如果使用时间长了,不免会因为速度的问题会去优化数据 […]
WordPress完美解决文章ID不连续问题
1,使用超级开关”super switch”,关闭文章修订版和自动保存 2,使用wp- […]
ASP.NET获取客户端及服务器的信息
ASP.NET获取客户端信息,暂时就这几个,有待添加~~ 1. 在ASP.NET中专用属性: 获取服务器电脑名 […]
.htaccess 封禁中国IP
首先强调一下这与爱国无关。 出于不同原因,很多站长需要封禁中国ip,特别是做英文站的朋友。因为对于Google […]
PHP操作mysql函数详解
PHP操作mysql函数详解,没有学过mysql和php交互的朋友可以自己看看这些函数 1. 建立和关闭连接 […]
zend debugger 与 zend optimizer和xdebug共存的方法
? 我用的是lamp集成环境是xampp,linux下是lampp,其实都是一个东西。 想改变一下自己老土的调 […]
PHP多版本共存解决方案
我这里说的php多版本共存不仅仅是php4、php5两个大版本号程序的共存,而是php的很多小版本号程序的共存 […]