file-io

Python open() append and read, file.read() returns empty string

谁说我不能喝 提交于 2020-01-11 09:33:32
问题 Noticed an odd behavior when attempting to call read() on a file opened in a+ mode (Python 3.4.1) As seen here File mode for creating+reading+appending+binary It's possible to open a file in read/append mode supposedly . However This code: with open("hgrc", "a+") as hgrc: contents=hgrc.read() returns contents={str}'' . Which is unexpected based upon the answer posted above. Now, the following code with open("hgrc", "r+") as hgrc: contents=hgrc.read() returns contents={str}'contents of hgrc...

java.security.AccessControlException: File accessible thru browser but not within same server

ε祈祈猫儿з 提交于 2020-01-11 07:17:22
问题 So to not repeat myself too much, please refer to serve static image along side java google-enpoint api. As you can see from the referenced link, I am able to view the image through the url. However, when I am trying to read filenames using similar code to public void listFilesForFolder(final File folder) { for (final File fileEntry : folder.listFiles()) { if (fileEntry.isDirectory()) { listFilesForFolder(fileEntry); } else { System.out.println(fileEntry.getName()); } } } final File folder =

File time stamp does not change with data update

风流意气都作罢 提交于 2020-01-11 06:10:53
问题 I have customer which claims that he has one application which updates the data in log file but that application does not change the time stamp of the log file. I have question why would any application has such behavior. 回答1: It's a new FEATURE of Windows 2008 (R2), Windows 7 and up. Modified time is not updated anymore like it used to in Windows 2003. http://blogs.technet.com/b/asiasupp/archive/2010/12/14/file-date-modified-property-are-not-updating-while-modifying-a-file-without-closing-it

File time stamp does not change with data update

左心房为你撑大大i 提交于 2020-01-11 06:10:29
问题 I have customer which claims that he has one application which updates the data in log file but that application does not change the time stamp of the log file. I have question why would any application has such behavior. 回答1: It's a new FEATURE of Windows 2008 (R2), Windows 7 and up. Modified time is not updated anymore like it used to in Windows 2003. http://blogs.technet.com/b/asiasupp/archive/2010/12/14/file-date-modified-property-are-not-updating-while-modifying-a-file-without-closing-it

file operation in binary vs text mode — performance concern

情到浓时终转凉″ 提交于 2020-01-11 04:47:24
问题 In many projects, I saw that data object/structure are written into file in binary mode, and then retrieve them back from the file in binary mode again. I wonder why they do it in binary mode? Any performance difference between text and binary mode? If not, then when to use binary mode or text mode? 回答1: Binary is faster. Consider an integer stored in 32 bits (4 bytes), such as 123456. If you were to write this out as binary (which is how it is represented in the computer) it would take 4

Setting Windows file security

好久不见. 提交于 2020-01-11 02:58:07
问题 My problem is the opposite that most people have. I'm generating files locally in C#, but I want them to be marked as blocked. So when a user opens them in an application like Word or Excel it opens them in "Protected Mode". I've read that this is set on "NTFS Alternate Data Streams". Does anyone know how I could mimick this in C#? 回答1: You need to write the alternate data stream yourself. To do this, open the file with CreateFile and write the text using FileStream. Here is a simple exemple

How to read numbers in python from csv file?

六眼飞鱼酱① 提交于 2020-01-11 02:26:07
问题 I have a csv file and I have to compute the mean for some of the columns. That's how I did: file=csv.reader(open('tab.csv','r')) n=[] for row in file: n.append(row[8]) So I have a list of string : n=['','','1.58'...] How can I convert these to float? I tried with : n_values=np.array(n) n_values[n=='']='0' values=n_values.astype(np.float) np.mean(values) But the mean is not correct because I should skip the empty strings not counting. Thank for your help! 回答1: Just cast as you append: n.append

Maximum File Size - supported in log4j FileAppender

半城伤御伤魂 提交于 2020-01-10 23:26:21
问题 I have a requirement that I need to store audit information in a TEXT file . I planned to write the audit information using Apache Log4j . Seems to be reliable option. But, I should be able to write the Audit information even the fileSize reaches 3GB. Does the log4j supports the fileSize even at GigaBytes ?. Or with a Quick Question, What is the MaximumFileSize can be supported in Log4j . NOTE : I could not go for RollingFileAppender or DailyFileAppender, I need to log the information Only in

Creating unflushed file output buffers

风流意气都作罢 提交于 2020-01-10 20:06:31
问题 I am trying to clear up an issue that occurs with unflushed file I/O buffers in a couple of programs, in different languages, running on Linux. The solution of flushing buffers is easy enough, but this issue of unflushed buffers happens quite randomly. Rather than seek help on what may cause it, I am interested in how to create (reproduce) and diagnose this kind of situation. This leads to a two-part question: Is it feasible to artificially and easily construct instances where, for a given

C Programming - Read specific line from text file

喜欢而已 提交于 2020-01-10 19:08:08
问题 Here is the code: int main() { struct vinnaren { char vinnare[20]; int artal; }; struct vinnaren v[10]; int inputrader; int antalrader; //I want antalrader to be equal to the first //line in test.txt(the first line is "5") char file_name[256] = "test.txt"; char buf[512]; FILE *f = fopen(file_name, "r"); if (!f) { exit(0); } while (fgets(buf, sizeof buf, f)) { printf("%s", buf); } fclose(f); } This is the code I have. I want to make it so that antalrader = line1 in the file test.txt How do I