io

FileNotFoundException in File.AppendAllText

假装没事ソ 提交于 2021-02-07 07:14:44
问题 I was reading File.AppendAllText method from msdn http://msdn.microsoft.com/en-us/library/ms143356.aspx I saw they have listed FileNotFoundException to possible exceptions list for the method but according to there description about method on the same page Opens a file, appends the specified string to the file, and then closes the file. If the file does not exist, this method creates a file, writes the specified string to the file, then closes the file. this part If the file does not exist,

FileNotFoundException in File.AppendAllText

和自甴很熟 提交于 2021-02-07 07:13:32
问题 I was reading File.AppendAllText method from msdn http://msdn.microsoft.com/en-us/library/ms143356.aspx I saw they have listed FileNotFoundException to possible exceptions list for the method but according to there description about method on the same page Opens a file, appends the specified string to the file, and then closes the file. If the file does not exist, this method creates a file, writes the specified string to the file, then closes the file. this part If the file does not exist,

ImageIO.write slow?

人走茶凉 提交于 2021-02-07 07:01:25
问题 I've an application where I'm writing around 25 png image files to disk every second. BufferedImage img = getBufferedImage(); // code below is very slow ~150ms. File file = new File(count++ + ".png"); BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(file)); ImageIO.write(img, "png", os); It usually takes 150ms per call, and achieving 25fps hence becomes impossible. Can I buffer IO so that I don't drop any frames? 回答1: PNG encoding takes a while and you can't improve it

fread() a struct in c

 ̄綄美尐妖づ 提交于 2021-02-07 06:44:52
问题 For my assignment, I'm required to use fread/fwrite. I wrote #include <stdio.h> #include <string.h> struct rec{ int account; char name[100]; double balance; }; int main() { struct rec rec1; int c; FILE *fptr; fptr = fopen("clients.txt", "r"); if (fptr == NULL) printf("File could not be opened, exiting program.\n"); else { printf("%-10s%-13s%s\n", "Account", "Name", "Balance"); while (!feof(fptr)) { //fscanf(fptr, "%d%s%lf", &rec.account, rec.name, &rec.balance); fread(&rec1, sizeof(rec1),1,

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

How can I associate a stream (FILE *) with stdout?

人走茶凉 提交于 2021-02-07 04:04:26
问题 Right now each module is writing to stderr, thus I cannot turnoff output of an individual one. Does anyone know how I can associate a stream with stdout thus each module will write to independent stream so I can turn it off. For example: fprintf(newStdout, "hello"); newStdout is writing to the screen. I don't know how to associate newStdout with the screen. 回答1: If your aim is to just have newStdout behave like stdout some of the time and silence it some of the time, you can do something like

Writing to a new directory in Python without changing directory

心已入冬 提交于 2021-02-06 10:21:14
问题 Currently, I have the following code... file_name = content.split('=')[1].replace('"', '') #file, gotten previously fileName = "/" + self.feed + "/" + self.address + "/" + file_name #add folders output = open(file_name, 'wb') output.write(url.read()) output.close() My goal is to have python write the file (under file_name) to a file in the "address" folder in the "feed" folder in the current directory (IE, where the python script is saved) I've looked into the os module, but I don't want to

How to read a line from stdin, blocking until the newline is found?

谁说胖子不能爱 提交于 2021-02-05 20:18:17
问题 I'm trying to read one line at a time, of arbitrary length, from stdin at the command line. I'm not sure if I'll be able to include GNU readline and would prefer to use a library function. The documentation I've read suggests that getline ought to work, but in my experiments it doesn't block. My sample program: #include <stdio.h> int main() { char *line = NULL; if (getline(&line, NULL, stdin) == -1) { printf("No line\n"); } else { printf("%s\n", line); } return 0; } produces No line , which