Improving performance of reading text from a large text file
来源:互联网 发布:贪心算法例题 编辑:程序博客网 时间:2024/04/29 09:41
KEYNOTE: Using containers such as StringBuilder and ArrayList<String> instead of String.
Before:
try {BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(f),"utf-8"));String str = "";String content = "";int counter = 0;while ((str = reader.readLine()) != null) {content += str + "\n";counter ++;if(counter % 1000 == 0)System.out.println(counter);} reader.close();} catch (Exception e) {// TODO Auto-generated catch blockSystem.out.println("[STEP1] - file to open the file.");}
After improving performance:
File f = new File(filename);String fileContent = "";StringBuilder builder = new StringBuilder();ArrayList<> model = new ArrayList<>();try {BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(f),"utf-8"));String str = "";int counter = 0;while ((str = reader.readLine()) != null) {// NOTE: String might reduce performancebuilder.append(str);counter ++;if(counter % 1000 == 0)System.out.println(counter);} reader.close();} catch (Exception e) {// TODO Auto-generated catch blockSystem.out.println("[STEP1] - file to open the file.");}
0 0
- Improving performance of reading text from a large text file
- Reading Text from Text Field
- Reading the bytes from a text file using a dispatch I/O channel
- How to open a large text file on Linux
- Reading records from a file
- Loading a text file
- 4.5.1.5 Executing SQL Statements from a Text File
- Display certain line(s) from a text file in Linux.
- Sample of C++ read/write a text file
- Reading Text Data Into A Unity Game
- Reading from a Binary File with BufferedInputStream
- reading data from a file storage
- Reading and Writing using a Large Random Access File
- Create Features from Text File (转)
- Download text file from JAX-RS
- On Reading this Text
- #Paper Reading# Bag of Tricks for Efficient Text Classification
- Converting a text file to a binary file
- 基于visual Studio2013解决面试题之0507字符串转整数
- JAXB学习二 (类型绑定)
- PHP 目录操作
- linux常用头文件之--linux/device.h
- 黑马程序员 eclipse的使用
- Improving performance of reading text from a large text file
- Struts类型转换器
- 黑马程序员_温习 GUI图形用户接口二 (个人笔记)摘要(综合应用---对话框----菜单----Jar包打开方法)
- AudioServicesPlaySystemSound音频服务—IOS开发
- 无论何时都要牢记自己的目标
- 移动APP推广--整个品牌-多一些APP
- Socket不能响应连接的问题 ( by quqi99 )
- AVAudioPlayer音频播放器—IOS开发
- Java高效开发框架Nutz:是SSH的轮子?还是新神器?