binaryfiles

Read binary file with a buffer

心不动则不痛 提交于 2019-12-08 07:01:28
I'm trying to read a binary file containing 100.000 different objects. buffering a simple text file with the same content takes only 2MB with a BufferedReader . But reading the binary files takes up to 700 MB and i get OutOfMemory error if I increase the number of objects to read. So how to read the file and get the objects one by one without saturating the memory? Here is the code I'm testing: public static void main(String[] args) throws Exception { int i = 0; String path = "data/file.bin"; InputStream file = new FileInputStream(path); InputStream buffer = new BufferedInputStream(file);

Reading Fortran binary file in Python

天大地大妈咪最大 提交于 2019-12-08 04:20:06
问题 I'm having trouble reading an unformatted F77 binary file in Python. I've tried the SciPy.io.FortraFile method and the NumPy.fromfile method, both to no avail. I have also read the file in IDL, which works, so I have a benchmark for what the data should look like. I'm hoping that someone can point out a silly mistake on my part -- there's nothing better than having an idiot moment and then washing your hands of it... The data, bcube1, have dimensions 101x101x101x3, and is r*8 type. There are

Read binary file with a buffer

▼魔方 西西 提交于 2019-12-08 03:27:56
问题 I'm trying to read a binary file containing 100.000 different objects. buffering a simple text file with the same content takes only 2MB with a BufferedReader . But reading the binary files takes up to 700 MB and i get OutOfMemory error if I increase the number of objects to read. So how to read the file and get the objects one by one without saturating the memory? Here is the code I'm testing: public static void main(String[] args) throws Exception { int i = 0; String path = "data/file.bin";

How should I write a struct to a file in C?

≯℡__Kan透↙ 提交于 2019-12-08 02:43:22
问题 I'm trying to write a struct to a binary file. I want my code to be cross platform, so I'm not sure about just writing the whole struct with a fwrite. If I did this, then the size of the struct will vary depending on the size of the primitive types for each platform(in platform A, an int won't have the same size as in platform B. So the struct won't be the same size either, and the file will end up being different). But I know nothing about this, so should I write each member of the struct

Reading and writing binary files in C++

感情迁移 提交于 2019-12-07 20:40:41
问题 I am entirely new to C++ with just a couple of hours self-teaching, that started yesterday. SO: I have a uncompressed simple beep.wav file, just about 3 seconds long with a single beeping sound in it. What I am ultimately trying to achieve is, just to read the file, and at the same time write the binary data, all including: the header , ftm and data or all that is hex readable data and dump it into a simple beep.txt file. is this possible, in C++? If so, how should I begin reading and dumping

Identifying the type of a file without extension from binary data

独自空忆成欢 提交于 2019-12-07 17:58:39
问题 I have some files without extension. I would like associate extensions to them. For that I have written a python program to read the data in the file. My doubt is how can I identify its type without the extension without using third party tools. I have to identify a pdf, doc and text file only. Other type of files are not possible. My server is cent os 回答1: You could read the first few bytes of the file and look for a "magic number". The Wikipedia page on magic numbers suggests that PDF files

Recursively search directory of binary files for hexadecimal sequence?

故事扮演 提交于 2019-12-07 16:31:17
问题 The current commands I'm using to search some hex values (say 0A 8b 02 ) involve: find . -type f -not -name "*.png" -exec xxd -p {} \; | grep "0a8b02" || xargs -0 -P 4 Is it possible to improve this given the following goals: search files recursively display the offset and filename exclude certain files with certain extensions (above example will not search .png files) speed: search needs to handle 200,000 files (around 50KB to 1MB) in a directly totaling ~2GB. I'm not too confident if the

Git Merge - Binary File Conflict Resolution

流过昼夜 提交于 2019-12-07 14:24:43
问题 How do I resolve a binary file conflict resolution during a merge operation in git? Here's what I've done so far: git checkout master git fetch origin git merge working_branch ... [Conflicts] ... git status ... Unmerged paths: both modified: Path/file.dll ... I want to keep the version in the working_branch and discard the version in the master . How do I do this? 回答1: Figured it out earlier today: git checkout --theirs Path/file.dll git add Path/file.dll git commit -m "Resolved merge

What is “Alignment” field in binary formats? Why is it needed?

北城以北 提交于 2019-12-07 09:38:52
问题 In ELF file format we have an Alignment field in Segment Header Table aka Program Header Table . In case of Windows PE file format they take it to next level the Sections have two alignment values, one within the disk file and the other in memory. The PE file header specifies both of these values. I didn't understand a thing about this alignment. What do we need it for? How & Where is it used? Again, I don't know what is alignment in binary file format context but why do we need it? 回答1: Well

Difference in writing string vs. char array with System.IO.BinaryWriter

荒凉一梦 提交于 2019-12-07 08:32:23
问题 I’m writing text to a binary file in C# and see a difference in quantity written between writing a string and a character array. I’m using System.IO.BinaryWriter and watching BinaryWriter.BaseStream.Length as the writes occur. These are my results: using(BinaryWriter bw = new BinaryWriter(File.Open(“data.dat”), Encoding.ASCII)) { string value = “Foo”; // Writes 4 bytes bw.Write(value); // Writes 3 bytes bw.Write(value.ToCharArray()); } I don’t understand why the string overload writes 4 bytes