fs

hdfs文件系统api操作

你。 提交于 2019-12-03 01:55:15
hdfs具体的安装方法参考前文(cm5.4和cdh5.4安装http://my.oschina.net/penngo/blog/517223) 这里只介绍java对hdfs文件系统的操作,下图是需要用到的包(这里包括hbase相关包) import java.io.IOException; import java.net.URI; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FSDataInputStream; import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; public class HdfsTest { private FileSystem fileSystem = null; private Configuration config = null; public HdfsTest() { } public void connect() throws Exception { String uri =

Remove string from txt file

放肆的年华 提交于 2019-12-03 00:04:57
问题 So basically I want to delete string from txt file. using fs Input Example: string1 string2 string3 string4 Delete string3 After delete It would be like: string1 string2 string4 回答1: Read the text file get the content in a variable then use String.replace For example var stringContent="Here goes the content of the textFile after read" var res=stringContent.replace('string3',''); //write back res to the file or do what ever 回答2: As brk answered, replace method on string will do the job.

Hadoop之HDFS(概述和Shell操作)

匿名 (未验证) 提交于 2019-12-02 23:54:01
HDFS HDFS组成架构 HDFS文 件块大小 HDFS Shell ) 1 bin/hadoop fs dfsfs实现 2.命令 $ bin/hadoop fs [-appendToFile <localsrc> ... <dst>] [-cat [-ignoreCrc] <src> ...] [-checksum <src> ...] [-chgrp [-R] GROUP PATH...] [-chmod [-R] <MODE[,MODE]... | OCTALMODE> PATH...] [-chown [-R] [OWNER][:[GROUP]] PATH...] [-copyFromLocal [-f] [-p] <localsrc> ... <dst>] [-copyToLocal [-p] [-ignoreCrc] [-crc] <src> ... <localdst>] [-count [-q] <path> ...] [-cp [-f] [-p] <src> ... <dst>] [-createSnapshot <snapshotDir> [<snapshotName>]] [-deleteSnapshot <snapshotDir> <snapshotName>] [-df [-h] [<path> ...]] [-du [-s] [-h] <path> .

node创建文件夹

匿名 (未验证) 提交于 2019-12-02 23:43:01
//mkdir.js const fs=require('fs'); const dirCache={}; function mkdir(filepath) { const arr=filepath.split('/'); let dir=arr[0]; for(let i=1;i<arr.length;i++){ if(!dirCache[dir]&&!fs.existsSync(dir)){ dirCache[dir]=true; fs.mkdirSync(dir); } dir=dir+'/'+arr[i]; } } module.exports=mkdir;

Callback function after image has downloaded

断了今生、忘了曾经 提交于 2019-12-02 21:59:35
I'm trying to save an image download with the request module. With this request('http://google.com/images/logos/ps_logo2.png').pipe(fs.createWriteStream('doodle.png')); It works fine. But I want to be able to do something else after the image has been completely downloaded. How can provide a callback function to fs.createWriteStream ? You want to create the stream ahead of time and then do something on the close event. var picStream = fs.createWriteStream('doodle.png'); picStream.on('close', function() { console.log('file done'); }); request('http://google.com/images/logos/ps_logo2.png').pipe

Remove string from txt file

安稳与你 提交于 2019-12-02 13:22:43
So basically I want to delete string from txt file. using fs Input Example: string1 string2 string3 string4 Delete string3 After delete It would be like: string1 string2 string4 Read the text file get the content in a variable then use String.replace For example var stringContent="Here goes the content of the textFile after read" var res=stringContent.replace('string3',''); //write back res to the file or do what ever As brk answered, replace method on string will do the job. Another way is var a = new Array(); a = string.split("searching_string"); string = a.join(""); Think it should work.

Write JSON with query pseudo

戏子无情 提交于 2019-12-02 10:55:41
I have a little website in node.js, when a people want to sign up we call a function (a external file) here the part where i write the JSON : { nouveauMembre = {}; nouveauMembre.pseudo = query.pseudo; nouveauMembre.password = query.password; listeMembre[listeMembre.length] = nouveauMembre; contenu_fichier = JSON.stringify(listeMembre); fs.writeFileSync("membres.json", contenu_fichier, 'utf-8'); } we write the pseudo and password in the JSON menbres.json but i want to write another file wich is call the actual pseudo selected (the query) so i write : nouveauMembre = {}; nouveauMembre.pseudo =

Why is this fs.readFile loop not pushing its results to my array? [duplicate]

放肆的年华 提交于 2019-12-02 09:39:46
This question already has an answer here: Why is my variable unaltered after I modify it inside of a function? - Asynchronous code reference 6 answers #!/usr/bin/env node var fs = require('fs') , async = require('async') , program = require('commander') program .version('0.0.1') .usage('<keywords>') .parse(process.argv) async.waterfall([ fs.readdir.bind(fs, __dirname), parseHTML, ], saveResult) function parseHTML(files, callback) { var result = [] files.forEach(function(file) { if (file.match(/\.html$/)) { fs.readFile(file, 'utf8', function(err, data) { if (err) throw err result.push(data) })

how save a physical image using fs extra with base64 text

落花浮王杯 提交于 2019-12-02 08:34:13
Please, could you help me? I would like to save an image, that is encoded in base64, using base64. I have tried this : var image = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAgAAAQABAAD/7QCcUGhvdG9zaG9wIDMuMAA4QklNBAQAAAAAAIAcAmcAFFd6cEFHZWltVEJyLURXbzBWeFlNHAIoAGJGQk1EMDEwMDBhYzAwMzAwMDBlOTA5MDAwMDRjMTIwMDAwOWMxMzAwMDAwNTE1MDAwMDlhMTkwMDAwOGMyMzAwMDBjNDI0MDAwMDRkMjYwMDAwZDkyNzAwMDBjYTM4MDAwMP

tail-stream module in nodejs is not printing last record of the file

北战南征 提交于 2019-12-02 08:00:05
I am using tail-stream to get data from a csv file and converting each csv record to json format and printing it. But tail-stream is not printing the last line of the file it is keeping it as a buffer, and if I update the file all the rows from previous last(the buffered last row) row to updated last row(excluding last row) are printed, its again storing the latest last row in buffer So is this the behavior of the tail-stream or is there any wrong in my code https://www.npmjs.com/package/tail-stream My code: var tailStream = require('tail-stream'); var Converter = require("csvtojson")