Read/write Java float[]

I'm looking for the quickest and most effecient way to read/write a float array (float[]) to file in a raw binary fashion.
In C I would do...
float fp = (float )malloc(sizeof(float)*nfloats);
// ... populate fp
int file = open("filename.bin", O_CREAT|O_WRONLY|O_TRUNC);
write(file, (void *)fp, sizeof(float)*nfloats);
close(file);
(forgive the lack of error checking etc. - for explanation purposes only)
So if in Java I have a...
float[] fp;
How dow I read/write fp to a file in a similar way?
Many thanks!

The easiest to program is java.net.DataInputStream.readFloat().
The most efficient is probably java.nio.FloatBuffer.get(), followed by java.nio.ByteBuffer.getFloat().

Similar Messages

  • Read&write binary float var to file

    Hello everybody.
    Oracle 11G R 2 on Linux.
    My problem.
    I have some millions of records (270.000.000)  with numeric data that can be store in binary float variables. Making the database work with so big table convert the database in a slow and hard to manage, because copys and so. The advantage is that this data only need be read, not modified or add news record.
    So, Im thinking to store in the file system, with UTL_FILE package, one or more binary files and access data through a algorithm to calculate the position of data inside the file. The data can be stored in binary float vars.
    My question.
    How I can add this binary data in binary format to the stream of write and read from the stream of data when I write to disk and when I read from disk.
    Any idea welcome.
    Thanks in advanced & regards everybody.

    I think that you dont understand the problem.
    The problem is easy, I have a table with 270.000.000 records. When you try to do anything with this table the database go slow, for your understand, when you ask a simple and easy query, by example a select count(*) from, it take more than 200 seconds to answer.
    ok, but the data is all numeric that can be stored in binary float var and moreover its position in a sequential file can be calculate.
    So if I make a sequential file, or more than one, where I can save this data I kick this problem to the database.
    And what I´m asking for help is if anybody know a way, using UTL_FILE, to include in the stream to save and read this data from disk (UTL_FILE.put_raw and UTL_FILE.get_raw) in binary float format, nothing more than this I want.
    You are correct that I 'dont understand the problem' because you yourself do not know what the 'problem' is.
    All you said is 'try to do anything with this table the database go slow' but you don't tell us what that 'anything' is. You give only ONE example.
    A COUNT(*) in Oracle could possibly use an index but you don't tell us if you have any indexes. You don't even provide the table DDL so we can see the structure.
    Your description gives the impression that all you have is a table with ONE column defined as BINARY FLOAT and that column is defined as NOT NULL. If that is the case you can create an index and Oracle can use it to get the COUNT(*) results.
    That ONE query is just about the only thing that might be faster with the data in a file. Since each value is four bytes and they can't be null then all you need to know is the length of the file. Then you can divide by four to find out how many entries there are.
    For anything else your 'file' solution will need to read the ENTIRE FILE to do anything other than access values as if the file was a large array of BINARY FLOAT four byte values.
    And for that, as I previously suggested, just forget Oracle and write a simple Java program that uses RandomAccessFile. Then for any given 'array' value just multiply by four, set the FilePointer value to that result and read your 4 bytes.

  • Asynchronous read & write by using Asynchronous api provided in nio-java 7

    HI,
    I am trying to write a small program to implement **asynchronous read & write by using Asynchronous api provided in nio in java 1.7** in windows machine.
    i tried the following code to write a small string to a file asynchronously.file is getting created but the contents are not dispalying.
         static long startTime = System.currentTimeMillis();
         static long endTime;
         static long execTime;
         public static void main(String[] args) {
              String path = "C:\\AsynchWrite.txt";
              Path file = Paths.get(path);
              final AsynchronousFileChannel channel;
              long pos = 1;
              try {
                   OpenOption[] options = { StandardOpenOption.CREATE,
                             StandardOpenOption.WRITE, StandardOpenOption.SYNC };
                   channel = AsynchronousFileChannel.open(file, options);
                   ByteBuffer buffer = ByteBuffer.allocate(1000);
                   String writeThis = "Testing by writing a line";
                   byte[] src = writeThis.getBytes();
                   buffer.put(src);
                   channel.write(buffer, pos, null,
                             new CompletionHandler<Integer, Object>() {
                                  @Override
                                  public void completed(Integer result, Object attachment) {
                                       System.out.println("completed successfully");
                                       System.out.println("start time :" + startTime);
                                       endTime = System.currentTimeMillis();
                                       System.out.println("end time : " + endTime);
                                       execTime = endTime - startTime;
                                       System.out.println("Execution Time :" + execTime);
                                       System.out.println("Execution Time(ms) :"
                                                 + execTime);
                                       try {
                                            channel.force(true);
                                            channel.close();
                                       } catch (IOException e) {
                                            // TODO Auto-generated catch block
                                            e.printStackTrace();
                                  @Override
                                  public void failed(Throwable exc, Object attachment) {
                                       // TODO Auto-generated method stub
                                       System.out.println("failed!!");
              } catch (IOException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
         }Please help me out
    Thanks in advance,
    Ravi

    It looks like you are missing buffer.flip() after your put as otherwise the buffer position will be at 25 (not 0 as you expect).

  • Java.util.PropertyPermission * read,write

    on tryieng to call my function i am getting this error .
    the Permission (java.util.PropertyPermission * read,write)
    has not been granted by dbms_java.grant_permission to
    SchemaProtectionDomain(JAVA|PolicyTableProxy(JAVA))
    what should i do to remove this error.
    null

    i got it running by executing
    DBMS_JAVA.GRANT_PERMISSION('JAVA','SYS:java.util.PropertyPermission', '*', 'read,write')
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Sherry:
    on tryieng to call my function i am getting this error .
    the Permission (java.util.PropertyPermission * read,write)
    has not been granted by dbms_java.grant_permission to
    SchemaProtectionDomain(JAVA|PolicyTableProxy(JAVA))
    what should i do to remove this error.
    <HR></BLOCKQUOTE>
    null

  • (java.util.PropertyPermission * read,write) has not been granted

    I've been getting the following error:
    java.security.AccessControlException:
    the Permission (java.util.PropertyPermission * read,write)
    has not been granted by dbms_java.grant_permission to
    SchemaProtectionDomain(ROVER|PolicyTableProxy(ROVER))
    So to fix it I did the flowing as system:
    SQL> EXEC DBMS_JAVA.GRANT_PERMISSION('ROVER','SYS:java.util.PropertyPermission', '*', 'read,write');
    PL/SQL procedure successfully completed.
    SQL> COMMIT;
    Commit complete.
    But their is no change.
    What am I missing?
    I'm using 8.1.6 on linux.

    I'm also in this situation:
    I got this error:
    [1]: (Error): ORA-29532: Java call terminated by uncaught Java exception:
    java.security.AccessControlException: the Permission
    (java.net.SocketPermission mailhost resolve) has not been granted by
    dbms_java.grant_permission to
    SchemaProtectionDomain(TOLKIEN|PolicyTableProxy(TOLKIEN)) ORA-06512: at line
    14
    I believe I must use the dbms_java.grant_permission procedure to grant the
    procedure to resolve hostname. But I don't know how to use this procedure.
    I tried with
    'dbms_java.grant_permission(SchemaOfMyJavaClass,'java.net.SocketPermission',
    'mailhost','resolve',intRet);'
    and a record is been appended to dba_java_policy, but Oracle complaines again.
    Someone can help us?
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Oracle Support():
    Can you see the permission in dba_java_policy table?
    <HR></BLOCKQUOTE>
    null

  • NEW Excel Read/Write Lib for JAVA

    FastExcel is a pure java excel read/write component.It's FAST and TINY. provide:
    * Reading and Writing support for Excel '97(-2003) (BIFF8) file format.
    * Low level structures for BIFF(Binary Interchange File Format).
    * Low level structures for compound document file format (also known as "OLE2 storage file format" or "Microsoft Office compatible storage file format").
    * API for creating, reading excel file.
    website http://fastexcel.sourceforge.net/
    Edited by: guooscar on Jun 18, 2009 7:44 PM

    guooscar wrote:
    cotton.m wrote:
    guooscar wrote:
    I read almost all of jxl source code and i try to use it to export/import data the result is slow&#65292;OOM&#65292;that&#146;s allOkay, fair enough.= _ =|||?
    At best this is a pretty specialized tool right? I mean 300,000,000 rows of data imported or exported (and I'm not sure which) daily from/to Excel is a bit of a wtf.
    But without formula support... it's sort of like the difference between a SAX and DOM parser.

  • Access registry (read/write) from java

    Hi folks,
    I'm struggeling with a Java/COM bridge to read/write the registry from my java application. The documentation from Sun on this is very sparely. Would be grateful for any hints!
    Regards,
    C.H. Liljegren

    Hi Bud,
    After a long time of asking everybody and then getting no response from any of the guys from the forum .I finally decided to do it myself and guess what I do succeded in reading and writing from the registry of windows from a Java program .
    I dont have the code now its there in my office . I will send it to u tomorrow .
    But one thing I came to know that if u wanna do some thing u have to take the initiative.
    I will send u the code tomorrow.
    Take Care.
    Manoj.

  • ATTN Java Gurus: udf.policy - Unable to Grant Read,Write to Specific File

    NOTE: A correct answer to this question will receive the rarely used OTN 25pt <font color="silver" size="3" face="script">Platinum Star</font><font color="silver" size="4" face="script"> &#9733;</font> *
    Essbase 9.3.1
    Using a Java CDF that reads and writes to a file
    I'm trying to grant permission to a specific file in the file system by granting permission in the udf.policy file.
    When I uncomment the line permission java.security.AllPermission; the CDF works fine and interacts with the file correctly. This is just to prove that the CDF works, I need to tighten this up to a single file. I stop and start the app after each edit.(I've also tried bouncing the Essbase server too)
    When I use the following, I get an exception, shown below. Nothing of consequence is being written to the app or essbase logs
    grant {
      permission java.io.FilePermission "C:/test/essbase/CalcProfile.db", "write, read";
    };java.security.AccessControlException: access denied (java.io.FilePermission C:\esstest\Server\PlugIns\Essbase read)
         at java.security.AccessControlContext.checkPermission(AccessControlContext.java:323)
         at java.security.AccessController.checkPermission(AccessController.java:546)
         at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
         at java.lang.SecurityManager.checkRead(SecurityManager.java:871)
         at com.hyperion.essbase.calculator.ESecurityManager.checkRead(ESecurityManager.java:80)
         at java.io.File.exists(File.java:731)
         at org.sqlite.Conn.open(Conn.java:98)
         at org.sqlite.Conn.<init>(Conn.java:57)
         at org.sqlite.JDBC.createConnection(JDBC.java:77)
         at org.sqlite.JDBC.connect(JDBC.java:64)
         at java.sql.DriverManager.getConnection(DriverManager.java:582)
         at java.sql.DriverManager.getConnection(DriverManager.java:207)
         at com.accelatis.essbase.calcprofile.cdf.CalcComment.calcComment(CalcComment.java:16)
    >
    I've tried creating the policy using PolicyTool, same result. However, I have no idea what or if I should put in the "CodeBase" field.
    Has anyone had success creating read & write permissions to a single file using the udf.policy file? What is the magic syntax?
    Regards,
    Robb Salzmann
    * <font face="small" size=".2em" color="silver">right after the platinum star award is created</font>

    Hi Robb,
    Never heard of the OTN 25pt Platinum Star award... It sounds appetizing, but I know I won't get it since I've got no Java experience. :)
    I was just gonna ask if you've thought about posting the same question on one of the Java forums?
    https://forums.oracle.com/forums/category.jspa?categoryID=285
    Cheers,
    Mehmet

  • How to write java code to read the pixel color in some place of screen?

    Hello all:
    How to write java code to read the pixel color in some place of screen?
    The java application iteself doesn't have any GUI.
    thank you
    -Danel

    See java.awt.Robot

  • Read&write Excel file using java

    Hi everybody,
    I have an assignment about methods that read and write an excel file using java (Eclipse SDK), so if anyone know about that please post the solution as soon as possible.
    Thanks
    Sendbad

    http://onesearch.sun.com/search/onesearch/index.jsp?qt=read+write+excel&subCat=siteforumid%3Ajava31&site=dev&dftab=siteforumid%3Ajava31&chooseCat=javaall&col=developer-forums

  • How To read/write file on remote server in java

    Hi All,
    How To read/write file on remote server in java? I mean using URL - http://www.xyz.com can I right file to that perticular server.
    Thanks in advance

    If your server support a means of uploading files you can.
    A popular means is [http://en.wikipedia.org/wiki/WebDAV]
    However, by default web server don't allow you upload files, its usually something you need to configure or install.
    I suggest you have a look at your web servers documentation.

  • Java card and reader/writer prices

    hi...I would like to know how much is a java card and how much is a reader/writer? thanks.

    You should implement your own session handling mechanism since the only type of session that is supported by JavaCard is HTTP, in version JC v3 (Connected version).
    Actually, I'm not even sure an HTTP session would suit your requirements.
    The easiest way to implement a session flag in your proposed system would be via a timestamp (saved in the Java Card applet).
    What does the following line mean?
    DOEACC@VIVS wrote:
    www.omnikey.com is best place

  • Pls How do I read/write a xml file using java

    I want to read/write trough a server/client a file.xml from evt. the same computer, this is the code for the client
    import java.io.*;
    import java.net.*;
    class client
    public static void main (String args[]) throws Exception
    final String msg = "<beg>note</beg>";
    // BufferedReader in = new BufferedReader(new FileReader("note.xml"));
    final Socket clientSocket = new Socket ("localhost", 8000);
    final OutputStream clientStream = clientSocket.getOutputStream ();
    clientStream.write (msg.getBytes ());
    // clientStream.write (in.getBytes ());
    clientSocket.close ();
    // BufferedReader in = new BufferedReader(new FileReader("note.xml"));
    // System.out.println(in.readLine());
    I want to read it and put it in a buffer...
    please somebody help me!!!
    regards
    Harry

    Pls read this:
    http://forum.java.sun.com/thread.jsp?forum=31&thread=271751
    And don't post the same message twice. It's annoying.

  • How to read/write a binary file from/to a table with BLOB column

    I have create a table with a column of data type BLOB.
    I can read/write an IMAGE file from/to the column of the table using:
    READ_IMAGE_FILE
    WRITE_IMAGE_FILE
    How can I do the same for other binary files, e.g. aaaa.zip?

    There is a package procedure dbms_lob.readblobfromfile to read BLOB's from file.
    http://download-east.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_lob.htm#sthref3583
    To write a BLOB to file you can use a Java procedure (pre Oracle 9i R2) or utl_file.put_raw (there is no dbms_lob.writelobtofile).
    http://asktom.oracle.com/pls/ask/f?p=4950:8:1559124855641433424::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:6379798216275

  • External Hard drive suddenly will only read! How can I make it read/write again?

    Hi folks,
    I'm working with a Seagate FreeAgent GoFlex 320gb External Hard Drive on the imacs here at my university. I have it formatted to ExFAT so that I could use it with my pc as well but I've never had to so far so it's only ever been used on the uni imacs.
    It's been fine for working on media projects until suddenly when i came back to uni after the Christmas break I went to continue working on a film project and realised the external hard drive now said read only??
    One thing I did was to put all of my work from last semester (which is everything that was on the hard drive into a single folder) could that have caused the problem?
    And does anyone know how i can reset my permissions to read/write without causing damage or risk to the files on the hard-drive as I can't clear the disk (i have no where else to store the 185gb of video footage).
    I'd really appreciate it if anyone could tell me how i can fix it? I know how to do all of this on my pc but i've no idea with the mac as i only use it for my media projects here in the university.
    Thanks!
    DrF ;-)

    Out of curiosity , will this method also work for an external drive formatted to NTFS.. I have a lot of data that I have nowhere to Float while re-formatting the drive , so If this method would allow me to keep the data and still fix the problem that would be great !!  At the moment the drive is formatted to NTFS and permissions say Read/Write , but I can only Read.. Very Frustrating as my mac drive is running low on space and performance is being affected.. Any help appreicated !!

Maybe you are looking for

  • Recording videos from Internet, with Apple software or from another company

    I know there's a way to record whatever sound is made by any application with Audio Hijack. Is there the video equivalent to Audio Hijack ? Does Apple make one? For example: Suppose there's a video playing in youtube or elsewhere on Internet through

  • Move a file to external disk and remove the original

    This is a script that was supplied to me on these forums it has been working well, but all the transferring of the files took place locally so a 'Move' command does it eactly what it says, however I now need to move it to an external drive, as a resu

  • How to Determine Length of variable up to period (.)

    I have  a variable called my_var  in an ABAP and it is passed many #'s  and they may or may not have some text following these #'s --- these #'s can have a  Length of up to 13 and will always have 3 Decimal Places.  I need to find a way to return the

  • Automate the database and forms / reports services to start on windows 2008 server R2 startup

    Dear memebers, I want to automate the database and forms / reports services to start on windows 2008 server R2 startup. whats the possibilities and which method is the best? Regards:

  • Approvals in SSHR

    Hi All, I am new to SSHR. We are using AME to manage approvals. We want to implement approval hierarchy for the actions in SSHR. We are sending the notification for approval to 2 superior at the most. We have three different kind of roles 1) Employee