Sponsored Content
Top Forums Programming How to replicate Ruby´s binary file reading with Java? Post 302926116 by achenle on Friday 21st of November 2014 09:24:02 AM
Old 11-21-2014
Quote:
Originally Posted by bakunin
I am no expert in Java, but i don't think this is possible. You probably have to do it yourself, like in good old C. You open a file (fopen()) and use fseek(), fread() and ftell() to find what you search for. The functions are part of the standard library, so they should work the same way in C and Java.

I hope this helps.

bakunin

AFAIK there's no way to use the stdio-based family of library calls (fopen(), etc.) and have them treat the binary sequence "FF47" as a "line" separator.

Even if you could set your LOCALE envvals to use a character set that uses "FF47" as a 16-bit character newline character (if one even exists), the fact that it's a binary file could break things - the "newline" character might not always be in a 16-bit boundary.

The only way to do what the OP asked is to read the file as a binary file, and search for the "FF47" bits. And hope that the way the file was written wasn't in a way that's endian-dependent. Especially when using Java on a little-endian machine (x86, most ARM OS's) as Java tends to read/write data in network byte order - big endian - for portability.
 

9 More Discussions You Might Find Interesting

1. Programming

Reading from a binary file

I'm having trouble with reading information back into a program from a binary file. when i try to display the contents of the file i get a Memory fault(coredump). would anyone be able to assist? this is my fread line fread(&file_data,sizeof(struct book_type),1,fileSave); ive also tried it without... (3 Replies)
Discussion started by: primal
3 Replies

2. Programming

Binary not getting executed from Java on Solaris environment

In the Java programme, I am calling function, "Runtime.getRuntime().exec( cmdarray ); " with the array of arguments in which first argument is the binary(C-executable) file and argv1,argv2 and so on. This will be executed on Sun OS system.. I can execute using "sh -c cmdarray" on the shell... (0 Replies)
Discussion started by: shafi2all
0 Replies

3. Shell Programming and Scripting

Reading Numerical Binary Data using KSH

Hi, I've searched and couldn't find anyone else with this problem. Is there anyway (preferably using ksh - but other script languages would do) that I can read in binary float data into a text file. The data (arrays from various stages of radar processing) comes in various formats, but mainly... (3 Replies)
Discussion started by: Jonny2Vests
3 Replies

4. Programming

Reading a binary file in text or ASCII format

Hi All, Please suggest me how to read a binary file in text or ASCII format. thanks Nagendra (3 Replies)
Discussion started by: Nagendra
3 Replies

5. Shell Programming and Scripting

reading fixed length flat file and calling java code using shell scripting

I am new to shell scripting and I have to to the following I have a flat file with storename(lenth 20) , emailaddress(lenth 40), location(15). There is NO delimiters in that file. Like the following str00001.txt StoreName emailaddress location... (3 Replies)
Discussion started by: willywilly
3 Replies

6. Shell Programming and Scripting

Running remote system shell script and c binary file from windows machine using java

Hi, I have an shell script program in a remote linux machine which will do some specific monitoring functionality. Also, have some C executables in that machine. From a windows machine, I want to run the shell script program (If possible using java). I tried with SSH for this. but, in... (1 Reply)
Discussion started by: ram.sj
1 Replies

7. Programming

reading binary files

#include <stdio.h> /* typedef struct { char name; int number; float balance; } acct_info_t; */ int main() { FILE *fptr; fptr = fopen("acct_info", "r"); int magic = 5; fseek(fptr,3,SEEK_SET); fread(&magic,sizeof(int),1,fptr);... (7 Replies)
Discussion started by: robin_simple
7 Replies

8. Programming

help with reading a binary file and fseek

this is my code and no matter what record number the user enters i cant get any of the records fields to read into the structure acct. What am i doing wrong? #include <stdio.h> typedef struct { char name; int number; float balance; } acct_info_t; int main (int... (0 Replies)
Discussion started by: bjhum33
0 Replies

9. Solaris

Reading binary content

Dear Gurus I am stuck with the peice of work and do not know from where to start. I get a machine generated file which is binary file contain binary data, i want to read binary data as it is without converting into any other format. i want to read byte by byte. Please let me know what... (24 Replies)
Discussion started by: guddu_12
24 Replies
_encodebinary64(3M)													       _encodebinary64(3M)

NAME
_encodebinary64(), _encodebinary128(), _encodebinary32() - encode binary-encoded decimal data SYNOPSIS
DESCRIPTION
There are two standard bit-encodings for decimal floating-point data: binary and decimal. Both encoding provide exactly the same data (analogous to big endian and little endian encodings). The HP-UX decimal floating-point types use the binary encoding. The function encodes x as a binary-encoded 64-bit decimal datum. is a version of it takes a argument and returns a result. is a version of it takes a argument and returns a result. These math functions are supported for HP-UX 11i Version 3 September 2008 Update and forward. USAGE
To use any of these functions, compile with the option. Make sure your program defines and then includes Link in the math library by specifying or on the linking command line. For more information, see the at the following site: RETURN VALUE
returns x in the binary encoding. raises no exceptions. ERRORS
No errors are defined. SEE ALSO
_decodebinary64(3M), _decodedecimal64(3M), _encodedecimal64(3M), math(5). STANDARDS CONFORMANCE
These functions are not specified in any standard. HP Integrity Server Only _encodebinary64(3M)
All times are GMT -4. The time now is 05:18 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy