wood burning stoves 2.0*
The moose likes Java in General and the fly likes Reading a file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Reading a file " Watch "Reading a file " New topic
Author

Reading a file

Yogesh Chhawasaria
Ranch Hand

Joined: Apr 02, 2004
Posts: 53
Hi,

Say theres one file of X MB and I want to read it entirely and display the decimal value represented by these X MB of data. Can anyone guide me how to begin with.

[By decimal value I mean : all bits finally represent something in decimal; How can I convert X MegaBits to Deciaml value and perform arithmetic operations on this value]

Thanks in advance


When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
I'm not sure whether i have understood u'r question fully ..

If u need a decimal value for each & every character in a file , why cant you use the ascii value of each character stored in the file .
[ October 17, 2004: Message edited by: srini vasan ]

Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
Are you perhaps talking about something like java.math.BigDecimal?
On the other hand - if you want to get a number that somehow characterizes the content of a large file, perhaps you want something like a message digest - see java.security.MessageDigest
Bill
Yogesh Chhawasaria
Ranch Hand

Joined: Apr 02, 2004
Posts: 53
Ill clarify my question once more

Say theres file of size 1kb These 1024 bytes (1kb) = 1024*16 bits must be representing a final decimal value
I need this decimal value and want to perform arithmetic computations on it.

Its easy to get that decimal value for small size file; for bigger files I used BIgInteger and somehow managed it. But after a fixed size I cannot sem to read entire file contents and get that final value maybe ram limitations

What I really want is that say theres a 2GB file then that file can be represented using a unique decimal(integer) value I just want to get that value but cant seem to...
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Well, with 2GB of data, you're going to bump into hard limitations of many JVMs. Sun's Linux and Windows JVMs both have heap size limits somewhat below 2GB. Your only option for directly dealing with data of this size would be to go to another language -- C/C++, probably -- and a 64 bit architecture. You can certainly play games whereby only part of the data comes into memory at once, but that adds a lot to the complexity of your code.

I'm quite interested now -- what sort of work are you doing that involves integers with 2 billion digits?


[Jess in Action][AskingGoodQuestions]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Reading a file
 
Similar Threads
Checking file size before uploading
get the resultant value upto 2 decimal places.
Decimals not converting to correct fractions
binay values
How to find number of decimal places?