file-io

Deleting parts of a data file in java

强颜欢笑 提交于 2019-12-24 21:39:04
问题 I have a file which I write some java objects. After writing, sometimes I need to delete some of these objects placed at ramndom positions in the file. Is there a way to delete a selected object from the file without replacing the whole file? Thank you. 回答1: No, this is fundamentally something that most file systems don't support. (There may be some with special data structures to make it cheap, but most don't - and the standard APIs don't support the idea.) The simplest way of "deleting"

How to get number of bytes that FileChannel.transferFrom wrote during it's writting

左心房为你撑大大i 提交于 2019-12-24 20:13:58
问题 HttpURLConnection conn = (HttpURLConnection) url.openConnection(); ReadableByteChannel rbc = Channels.newChannel(conn.getInputStream()); FileOutputStream fos = new FileOutputStream(fileName); FileChannel fch = fos.getChannel(); fch.transferFrom(rbc, 0, Long.MAX_VALUE); I debugged it and reaches the next line of code after the download is completed. How can I get the number of bytes that transferFrom() wrote during it's writing a file, to write it to a log or to the console? Something like

C function fwrite() doesn't write in file

做~自己de王妃 提交于 2019-12-24 17:20:04
问题 I'm trying to write structures from tempGroupFile into GroupFile . fwrite() returns 1, when writing, but actually no data is written in the file GroupFile . Function printRec() prints out the structure on the screen. data is a variable of structure. File GroupFile is empty after these operations. Code: GWTemp = fopen(tempGroupFile, "rb"); GW = fopen(GroupFile, "wb"); if((GW == NULL) || (GWTemp == NULL)) { puts("Failed to open file."); fflush(stdin); getchar(); return 0; } while(fread(&data,

java storing output from file into an array

喜夏-厌秋 提交于 2019-12-24 16:31:56
问题 I have a question on how to store output from a file into an array. In my case, I am trying to store all the date in a file into an array. For the way that I did it, the compiler complains "not a statement". How can I fix this? Any help will be greatly appreciated. Below is my code (the line of error is preceded by backslashes): double token[] = new double[9]; File filename = new File("/Users/timothylee/gravity1.txt"); Scanner inFile = new Scanner(filename); while(inFile.hasNext()){ /////////

Reading files from hard drive with javascript

回眸只為那壹抹淺笑 提交于 2019-12-24 14:57:36
问题 My application creates .xml files and stores them on the user's hard drive; there is a default folder that I set in the web.xml to store the files, let's say D:/temp . Now after I write the files I need to read them back with javascript, I am using a javascript library that has this function mxUtils.load('URL of the file') (this function returns the content of the file), the problem is that it is giving me an error Cross origin requests are only supported for HTTP , (I now it doesn't have

Perl Imgsize not working in loop?

若如初见. 提交于 2019-12-24 13:59:56
问题 I've tested getting the image size using perl with the following simple code while sitting in one directory: #!/usr/local/bin/perl use Image::Size; my $x; my $y; my $id; opendir my $dh, "." or die "$0: opendir: $!"; ($x, $y, $id) = imgsize("test_image.png"); print $x." , ".$y."\n"; This worked fine, it gave me the correct width and height of the image. Then I incorporated it into my larger code, where I'm looping through folders and files. So the bigger code is this: # I first get into a

Filling structure from a file

别来无恙 提交于 2019-12-24 13:38:23
问题 Hey guys i am doing a project at school and i need to fill an array of pointers with info from a text doc: 4101 BRAEBURN_REG 1 0.99 101.5 4021 DELICIOUS_GDN_REG 1 0.89 94.2 4020 DELICIOUS_GLDN_LG 1 1.09 84.2 4015 DELICIOUS_RED_REG 1 1.19 75.3 4016 DELICIOUS_RED_LG 1 1.29 45.6 4167 DELICIOUS_RED_SM 1 0.89 35.4 4124 EMPIRE 1 1.14 145.2 4129 FUJI_REG 1 1.05 154.5 4131 FUJI_X-LGE 1 1.25 164.1 4135 GALA_LGE 1 1.35 187.7 4133 GALA_REG 1 1.45 145.2 4139 GRANNY_SMITH_REG 1 1.39 198.2 4017 GRANNY

Invalidate OS disk read cache

时间秒杀一切 提交于 2019-12-24 13:26:35
问题 I'm trying compare the performance of a windows program when the disk cache is in its best state (when all files needed for the program to run are in memory cache, I just run it multiple times to get this state), and when the cache is in its worst state, that is completely empty. The only way way I know to ensure that the cache is completely empty is by rebooting the computer, but this is not ideal since its takes too much time. Is there any way to do this without rebooting? I tried sync, but

How do I scan in numbers to an array from a file?

♀尐吖头ヾ 提交于 2019-12-24 13:09:41
问题 Say I have a file with the numbers: 1 2 3 4 5 6 7 8 9 10 -1 I want to read in that file and store all the values of that file, stopping at the control variable -1. So if I printed that array to another file it would look like: 1 2 3 4 5 6 7 8 9 10 This gives me all the numbers, but it has -1 included. How can I drop off the -1? int arr[100]; int n; while (scanf("%d",&arr[n]) > 0) n++; 回答1: You cannot add the > 0 condition: this would give you undefined behavior. In order to ignore the

Python: interdependent process/thread queues

青春壹個敷衍的年華 提交于 2019-12-24 12:45:33
问题 I have four queues that each have multiple processes/threads that are interdependent in the following way: Queue 1 is reading a file from disk and copying to RAM Queue 2 takes the file in RAM and performs an operation on it Queue 3 takes the result of Queue 2 and performs a separate operation on it Queue 4 writes the end result back to disk I would like these 4 queues to operate in parallel as much as possible with the caveat that Queue 2 has to wait for Queue 1 to place at least one process