I'm having a file with binary Unicode (mean file contain Unicode value of corresponding data (text file)), want to divide that as blocks with the size of 144bits. I don't know how to code for this so please kindly help me.
Printable View
I'm having a file with binary Unicode (mean file contain Unicode value of corresponding data (text file)), want to divide that as blocks with the size of 144bits. I don't know how to code for this so please kindly help me.
What have you tried?
Can you read the file as bytes: 144/8 at a time?
Of course, we can read it as bytes too.So we will get 18 bytes. Can you please help me in that coding for block division?
What have you tried? The FileInputStream class has method for reading bytes.
I have used FileInputStream class but its not working properly to divide the bits into blocks.I will attach the coding,help me out to fix the problem.
public static void main(String[] args) {
ReadFileExample newclass = new ReadFileExample();
System.out.println("cryptography");
File input = new File("D:/java/source.txt");
File output = new File("D:/java/target.txt");
byte[] block = new byte[18];
try {
FileInputStream fis = new FileInputStream(input);
FileOutputStream fos = new FileOutputStream(output);
//CipherOutputStream cos = new CipherOutputStream(fos);
System.out.println("Total file size to read (in bytes) : "
+ fis.length());
int i;
while ((i = fis.read(byte[18]))!= -1) {
System.out.println(block);
fos.write(block, 0, i);
}
fos.close();
}
catch (Exception e)
{
System.out.println("invalid");
}
}}
Please edit the post and wrap the code in code tags to make it easier to read.
can you explain what that means? If there are errors, please copy the full text and paste it here.Quote:
its not working
Also posted at: http://www.javaprogrammingforums.com...ptography.html
The error is that the code could not block divide the bits. It just reads the bits from the input file and writes the same as it is to the input text file without dividing them into blocks. Error appears in the 'while loop' too. What's wrong in that?
Please copy the full text of the error message and paste it here. You need to fix the error before you can test the code.Quote:
Error appears
Please edit your post and wrap your code with code tags:
[code]
YOUR CODE HERE
[/code]
to get highlighting and preserve formatting.