file

How do I Monitor Text File Changes with C++? Difficulty: No .NET

别说谁变了你拦得住时间么 提交于 2021-02-07 07:57:54
问题 Use case: 3rd party application wants to programatically monitor a text file being generated by another program. Text file contains data you want to analyze as it's being updated. I'm finding a lot of answers to this question wrapped around FileSystemWatcher but let's say you are writing an application for a Windows machine and can't guarantee .NET is installed. Are there any libraries out there available for this, or am I just going to have to roll my own solution then? Thanks. 回答1: You can

Reading changing file in Python 3 and Python 2

老子叫甜甜 提交于 2021-02-07 06:56:59
问题 I was trying to read a changing file in Python, where a script can process newly appended lines. I have the script below which prints out the lines in a file and does not terminate. with open('tmp.txt','r') as f: while True: for line in f: print(line.replace('\n','')) Where 'tmp.txt' consists of some lines, e.g.: a d 2 3 If I appended to the 'tmp.txt' file, such as using: echo "hi" >> tmp.txt The script will print out the new line in if the script is run with Python 3, but not with Python 2.

Reading a file from a hard drive in iPhone simulator

北慕城南 提交于 2021-02-07 06:46:46
问题 Is it possible to read a file (from my normal file system) into a iPhone App running on the iPhone Simulator? I understand that the iPhone itself has not got a (user accessible) file system but this is simply for testing and will only ever be run in the simulator. The file will be a text file that can be edited while the application is running, it will be read every-time a method is called. 回答1: Yes, you can, and it doesn't matter where it is. Just give it an absolute path name when you load

How can i sort large csv file without loading to memory

拜拜、爱过 提交于 2021-02-07 05:27:22
问题 I have 20GB+ csv file like this: **CallId,MessageNo,Information,Number** 1000,1,a,2 99,2,bs,3 1000,3,g,4 66,2,a,3 20,16,3,b 1000,7,c,4 99,1,lz,4 ... I must order this file by CallId and MessageNo as asc. (One way is load database->sort->export) How can i sort this file without loading all lines to memory in c#? (like line by line using streamreader) Do you know a library for solution? i wait your advice, thanks 回答1: You should use OS sort commands. Typically it's just sort myfile followed by

How to open all files that starts with specific prefix in java?

余生长醉 提交于 2021-02-07 05:26:05
问题 Is there any way to open some of the text files in the directory that starts with a specific name in Java? For example in my directory I have the following files: Ab-01.txt Ab-02.txt Ab-03.txt Ab-04.txt SomethingElse.txt NotRelated.txt So now in my Java code I only want to open those files that starts with “ Ab- “ 回答1: Yes. Use File.listFiles(FilenameFilter): As an example: File dir = new File("/path/to/directory"); File[] foundFiles = dir.listFiles(new FilenameFilter() { public boolean

Golang, a proper way to rewind file pointer

北城以北 提交于 2021-02-07 05:07:38
问题 package main import ( "bufio" "encoding/csv" "fmt" "io" "log" "os" ) func main() { data, err := os.Open("cc.csv") defer data.Close() if err != nil { log.Fatal(err) } s := bufio.NewScanner(data) for s.Scan() { fmt.Println(s.Text()) if err := s.Err(); err != nil { panic(err) } } // Is it a proper way? data.Seek(0, 0) r := csv.NewReader(data) for { if record, err := r.Read(); err == io.EOF { break } else if err != nil { log.Fatal(err) } else { fmt.Println(record) } } } I use two readers here to

Golang, a proper way to rewind file pointer

做~自己de王妃 提交于 2021-02-07 05:07:34
问题 package main import ( "bufio" "encoding/csv" "fmt" "io" "log" "os" ) func main() { data, err := os.Open("cc.csv") defer data.Close() if err != nil { log.Fatal(err) } s := bufio.NewScanner(data) for s.Scan() { fmt.Println(s.Text()) if err := s.Err(); err != nil { panic(err) } } // Is it a proper way? data.Seek(0, 0) r := csv.NewReader(data) for { if record, err := r.Read(); err == io.EOF { break } else if err != nil { log.Fatal(err) } else { fmt.Println(record) } } } I use two readers here to

Golang, a proper way to rewind file pointer

故事扮演 提交于 2021-02-07 05:06:23
问题 package main import ( "bufio" "encoding/csv" "fmt" "io" "log" "os" ) func main() { data, err := os.Open("cc.csv") defer data.Close() if err != nil { log.Fatal(err) } s := bufio.NewScanner(data) for s.Scan() { fmt.Println(s.Text()) if err := s.Err(); err != nil { panic(err) } } // Is it a proper way? data.Seek(0, 0) r := csv.NewReader(data) for { if record, err := r.Read(); err == io.EOF { break } else if err != nil { log.Fatal(err) } else { fmt.Println(record) } } } I use two readers here to

Open file by its full path in C++

寵の児 提交于 2021-02-07 04:52:53
问题 I want the user to give me the full path where the file exists and not just the file name. How do I open the file this way? Is it something like this: ifstream file; file.open("C:/Demo.txt", ios::in); This doesn't seem to work. 回答1: Normally one uses the backslash character as the path separator in Windows. So: ifstream file; file.open("C:\\Demo.txt", ios::in); Keep in mind that when written in C++ source code, you must use the double backslash because the backslash character itself means

Node.js How to delete first line in file

梦想的初衷 提交于 2021-02-06 15:20:46
问题 I'm making simple Node.js app and I need to delete first line in file. Please is any way how to do it? I think that It will be possible with fs.write, but how? 回答1: Here is streamed version of removing first line from file. As it uses streams, means you don't need to load whole file in memory, so it is way more efficient and fast, as well can work on very large files without filling memory on your hardware. var Transform = require('stream').Transform; var util = require('util'); // Transform