lineReader 文件上传MySQL(可读每行)
来源:互联网 发布:出身不好知乎 编辑:程序博客网 时间:2024/06/05 14:52
var fs = require("fs");
var lineReader = require('line-reader');
var async = require("async");
var readFile= require("./路径/readFileDao");
function run(){
var path = 'E:/'; //设置读取文件路径
explorer(path);
}
run();
function explorer(path){
fs.readdir(path, function(err,files){ //读取路径下所有文件
if(err){
console.log("error:\n"+err);
return;
}else{
async.mapSeries(files, function(file, callback) { //将文件逐一循环出
var index = 0;
var id = "";
var title = "";
var content = "";
lineReader.eachLine(path+file, function(line, last) { //path+file请保证为文件路径+文件名 line为文件每行内容
index ++;
if (index == 1) {
id = id + line;
} else if (index == 2) {
title = title + line;
} else if (index >= 4) {
content = content + line;
}
if(last){ //判断如为最后一行执行
var orderThing = {};
orderThing.id = id;
orderThing.title = title;
orderThing.content = content;
readFile.readFile中的自定接口(orderThing, function(err, result){
if(err){
callback(err);
return;
}else{
callback(null);
return;
}
});
}
});
}, function(err) {
if(err){
console.info(err);
console.info('read data error');
return;
}else{
console.info('read data success');
return;
}
});
}
});
}
var lineReader = require('line-reader');
var async = require("async");
var readFile= require("./路径/readFileDao");
function run(){
var path = 'E:/'; //设置读取文件路径
explorer(path);
}
run();
function explorer(path){
fs.readdir(path, function(err,files){ //读取路径下所有文件
if(err){
console.log("error:\n"+err);
return;
}else{
async.mapSeries(files, function(file, callback) { //将文件逐一循环出
var index = 0;
var id = "";
var title = "";
var content = "";
lineReader.eachLine(path+file, function(line, last) { //path+file请保证为文件路径+文件名 line为文件每行内容
index ++;
if (index == 1) {
id = id + line;
} else if (index == 2) {
title = title + line;
} else if (index >= 4) {
content = content + line;
}
if(last){ //判断如为最后一行执行
var orderThing = {};
orderThing.id = id;
orderThing.title = title;
orderThing.content = content;
readFile.readFile中的自定接口(orderThing, function(err, result){
if(err){
callback(err);
return;
}else{
callback(null);
return;
}
});
}
});
}, function(err) {
if(err){
console.info(err);
console.info('read data error');
return;
}else{
console.info('read data success');
return;
}
});
}
});
}
0 0
- lineReader 文件上传MySQL(可读每行)
- 从rich edit里每行的读取,可读中文内容
- 每行读取文件
- prim算法,可读取文件
- LineReader和LineRecordReader
- hadoopAPI之LineReader类
- MySQL判断是否有数据可读源码
- 天翼云一处xxe漏洞可读取任意文件
- seq_file接口创建可读写proc文件
- access测试文件是否可读/可写
- python实现图片转化成可读文件
- 利用mysql上传和执行文件
- servlet + JSP+ mysql实现文件的上传
- servlet + JSP+ mysql实现文件的上传
- mysql如何上传导入大文件sql
- Mysql 解决 phpMyAdmin 上传文件 最大限制
- 在文件中每行开头加上行号
- awk 计算文件中每行的值
- 操作系统——进程管理
- Mongodb数据库与springmvc整合
- UItableview的一些总结
- Swift-基本运算符
- 给定单链表的头指针和一个结点指针,定义一个函数在O(1)时间删除该节点
- lineReader 文件上传MySQL(可读每行)
- C++第6次作业
- 2016 百度之星资格赛 Problem C (Trie模板)
- 菜鸟上路,杭电OJ1002之大数相加
- 委托事件(未完待续...)
- 【android】:android与java的关系
- jQuery 的选择器
- Activity的四种启动模式
- Matlab R2015b怎么把界面改为中文/英文