Results 1 to 4 of 4
- 02-10-2013, 08:54 PM #1
Member
- Join Date
- Feb 2013
- Posts
- 1
- Rep Power
- 0
Converting a string of binary to data, to save to a file
Hello everyone. Recently, I've been working on the task of converting a file to a string of binary, converting that string of binary to a sound, and then converting that back to a string of binary. The problem is, after I convert back to binary, I can't figure out how to convert that binary string to data so I can save it to a file, and re-create the file. The reason I'm not posting and code for this post is I literally have no idea on how to go about saving a string of binary to a file. I did a good 20 minutes of searching and came up with no results for this issue. Any help would be very appreciated.
Ex, if I had
As a string, how would I convert that string of binary into the original file?Java Code:101010011001011110011111010011000111000011100001110000111000011100001110000111000011100001110000111000011100001110000111001011001011001011001011001011001011001011001011001011001011001011001011001011 0001110001110001110001110001110001110001110001110001110001
- 02-11-2013, 07:29 AM #2
Member
- Join Date
- Feb 2013
- Posts
- 2
- Rep Power
- 0
Re: Converting a string of binary to data, to save to a file
Use obJectOutputStream
- 02-11-2013, 07:36 AM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
Re: Converting a string of binary to data, to save to a file
That depends on the content of the original file, i.e. if the original content were a bunch of ints, I'd break up the String into 32 bit chunks and convert each to an int; but it all depends on the way the original file was encoded into a binary String ...
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 02-11-2013, 07:40 AM #4
Member
- Join Date
- Feb 2013
- Posts
- 2
- Rep Power
- 0
Re: Converting a string of binary to data, to save to a file
Sample Code of Dealing with binary file
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.Date;
public class ObjectIOApp {
public static void main(String args[]) throws IOException, ClassNotFoundException {
File file = new File("test.txt");
FileOutputStream outFile = new FileOutputStream(file);
ObjectOutputStream outStream = new ObjectOutputStream(outFile);
TestClass1 t1 = new TestClass1(true, 9, 'A', 0.0001, "java");
TestClass2 t2 = new TestClass2();
String t3 = "This is a test.";
Date t4 = new Date();
outStream.writeObject(t1);
outStream.writeObject(t2);
outStream.writeObject(t3);
outStream.writeObject(t4);
outStream.close();
outFile.close();
FileInputStream inFile = new FileInputStream(file);
ObjectInputStream inStream = new ObjectInputStream(inFile);
System.out.println(inStream.readObject());
System.out.println(inStream.readObject());
System.out.println(inStream.readObject());
System.out.println(inStream.readObject());
inStream.close();
inFile.close();
file.delete();
}
}
Similar Threads
-
converting binary to string
By stegano in forum New To JavaReplies: 5Last Post: 03-27-2011, 07:20 PM -
GUI: How to save these data to a text/dat file?
By florachu2121 in forum New To JavaReplies: 6Last Post: 08-01-2010, 11:31 PM -
Create a form, input some data and save to file
By cselic in forum AWT / SwingReplies: 5Last Post: 05-07-2010, 12:28 PM -
Read a file and converting this file into a string
By kostinio in forum New To JavaReplies: 7Last Post: 12-26-2009, 03:54 PM -
Converting a text file int binary
By sruthi_2009 in forum New To JavaReplies: 0Last Post: 03-23-2009, 03:09 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks