文件生成(做测试时使用)
2011-06-13 10:05
148 查看
public class test {
/** * @param args * @throws Exception */ public static void main(String[] args) throws Exception { // TODO Auto-generated method stub File f = new File("c:\\aa.pdf"); for(int i=0;i<1100;i++) { File n = new File("c:\\pdf\\REPORT_1306460911500"+i+".pdf"); forChannel(f,n); } } public static long forChannel(File f1,File f2) throws Exception{ long time=new Date().getTime(); int length=2097152; FileInputStream in=new FileInputStream(f1); FileOutputStream out=new FileOutputStream(f2); FileChannel inC=in.getChannel(); FileChannel outC=out.getChannel(); ByteBuffer b=null; while(true){ if(inC.position()==inC.size()){ inC.close(); outC.close(); return new Date().getTime()-time; } if((inC.size()-inC.position())<length){ length=(int)(inC.size()-inC.position()); }else length=2097152; b=ByteBuffer.allocateDirect(length); inC.read(b); b.flip(); outC.write(b); outC.force(false); } }}
/** * @param args * @throws Exception */ public static void main(String[] args) throws Exception { // TODO Auto-generated method stub File f = new File("c:\\aa.pdf"); for(int i=0;i<1100;i++) { File n = new File("c:\\pdf\\REPORT_1306460911500"+i+".pdf"); forChannel(f,n); } } public static long forChannel(File f1,File f2) throws Exception{ long time=new Date().getTime(); int length=2097152; FileInputStream in=new FileInputStream(f1); FileOutputStream out=new FileOutputStream(f2); FileChannel inC=in.getChannel(); FileChannel outC=out.getChannel(); ByteBuffer b=null; while(true){ if(inC.position()==inC.size()){ inC.close(); outC.close(); return new Date().getTime()-time; } if((inC.size()-inC.position())<length){ length=(int)(inC.size()-inC.position()); }else length=2097152; b=ByteBuffer.allocateDirect(length); inC.read(b); b.flip(); outC.write(b); outC.force(false); } }}
相关文章推荐
- IT咨询顾问:一次吐血的项目救火 java或判断优化小技巧 asp.net core Session的测试使用心得 【.NET架构】BIM软件架构02:Web管控平台后台架构 NetCore入门篇:(十一)NetCore项目读取配置文件appsettings.json 使用LINQ生成Where的SQL语句 js_jquery_创建cookie有效期问题_时区问题
- Python之使用unittest框架和HTMLTestRunner.py文件实现多个测试用例执行与测试报告生成
- iOS 打包程序生成 .ipa文件, 生成可内部测试的二维码(使用x-code7.0)
- 使用Maven自动打包配置文件生成开发环境,测试环境,生产环境
- 使用C#从图片文件生成图标ICON文件(附源文件)
- 使用CodeSmith快速生成映射文件和映射类
- 使用Apache POI生成和读取excel文件
- fatal error C1047 对象或库文件“....Win32Release xxx.obj”是使用比创建其他对象所用编译器旧的编译器创建的;请重新生成旧的对象和库[转]
- 使用Python3生成CSV文件遇到的问题(空行/乱码)
- Android NDK学习(4)使用cygwin生成.so库文件
- 不使用Cygwin,在eclipse中快速开发JNI,一键生成C头文件.h,以及一键使用NDK交叉编译
- Python:随机生成测试数据的模块--faker的基本使用
- Cocos2d使用TexturePacker工具打包生成plist和pvr.ccz文件方法总结
- tags文件生成及使用
- Iozone 文件系统的读写性能测试工具的使用
- 在Eclipse中使用Axis2插件自动生成WSDL文件
- C++使用TinyXML生成和解析xml文件
- linux 库文件 生成与使用
- Linux下使用automake、autoconf生成configure文件
- DMP文件的生成和使用