Results 1 to 6 of 6

Thread: File byte array to save in database

  1. #1
    Join Date
    Dec 2009
    Posts
    178

    File byte array to save in database

    Hello,
    I would like to create from a file, byte arrays to save it in a database. Also I'd like to have an inverse function to recreate the file from an array of bytes. How do I do this? I have this method but they only work on the file which is less than 64k.
    Code:
    Public void tanle (byte[] table, String ex) throws java.io.IOException {
    		try {
    		    java.io.FileWriter flwr = new java.io.FileWriter(flwric);
    		    flwror (int i = 0; I <array.length; I + +) {
       			    flwr.write((int)board[i]);
    	    	}	 
    			flwr.close();
    		}
    		catch(IOException e){
    			System.out.System.out.println(e +"Error reading flwrile");
    		}    
    	}

  2. #2
    Join Date
    Apr 2008
    Posts
    2,005

    Re: File byte array to save in database

    Hello,
    I'm not sure but, you have an Exception or Error strike while running? ex.length make what changes to your code? If you did not get error on creating table with a size> 65540, then the problem occurs from which part of the code. It's weird, I thought the size of the tables was limited to the max size value of INT, but this is not the case. It is not just a memory problem? Hope I am correct?

  3. #3
    Join Date
    Dec 2009
    Posts
    178

    Re: File byte array to save in database

    Hello,
    In fact, look at the for loop
    Code:
    for (int i = 0; i <array.length; i + +) {
       			    flwr.write((int)board[i]) };
    This only works if the tanle.lenght exceeds the size of int. It's just the problem, I will need another method to store the data in the file. Would you recommend me any other method to this.

  4. #4
    Join Date
    Feb 2008
    Posts
    1,852

    Re: File byte array to save in database

    Hi,
    So I have not tested but if you use classes from java.sql package to retrieve your data, then you get a ResultSet where you make a
    getBlob ();
    Then you can copy the stream to a file. For that you recover the
    Code:
    InputStream (exBlob.getBinaryStream ())
    In this way you can copy the stream of data into your specified file.

  5. #5
    Join Date
    May 2008
    Posts
    2,389

    Re: File byte array to save in database

    Hi,
    I think in fact it is easier to retrieve an object directly by Blob. Regarding your code, it is normal that the method is problematic because you use a buffer containing reading, apparently to your entire file. Outside the buffer should not exceed the amount of available memory. For the method, I see no reason why you meet error. However, I think the method file.length () returns the size declared in the file properties, and this statement may be false. It is best to assume that one knows in advance the size of the file.

  6. #6
    Join Date
    Dec 2009
    Posts
    178

    Re: File byte array to save in database

    Hello,
    Thank you for your help, my problem is solved. This is how I modified my code and the method look some what like this, though this is not the final implementation of the method.
    Code:
    		java.io.File fl = new File(fi);
    		try {
    		FileOutputStream f = new FileOutputStream(fl);
    As i used directly the File type it did not reaturned the file integrity, that is why i was getting an error in my code. By the thanks again for your help.

Similar Threads

  1. How to save excel file as Database 3
    By Aarti C in forum Windows Software
    Replies: 3
    Last Post: 08-01-2012, 01:54 PM
  2. Can't delete 0 byte file, with no file type
    By Adele2 in forum Windows XP Support
    Replies: 8
    Last Post: 15-12-2009, 12:33 PM
  3. How to store byte array to database with JDBC?
    By RogerFielden in forum Software Development
    Replies: 3
    Last Post: 23-09-2009, 10:52 AM
  4. Fill an array using a mysql database
    By Jacek in forum Software Development
    Replies: 3
    Last Post: 16-04-2009, 12:12 AM
  5. Failed to save Local Policy Database
    By Russell in forum Windows Security
    Replies: 3
    Last Post: 08-11-2007, 06:23 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,199,031.83495 seconds with 17 queries