CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: Block division

Hybrid View

  1. #1
    Join Date
    Feb 2014
    Posts
    6

    Block division

    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.

  2. #2
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: Block division

    What have you tried?

    Can you read the file as bytes: 144/8 at a time?
    Norm

  3. #3
    Join Date
    Feb 2014
    Posts
    6

    Re: Block division

    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?

  4. #4
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: Block division

    What have you tried? The FileInputStream class has method for reading bytes.
    Norm

  5. #5
    Join Date
    Feb 2014
    Posts
    6

    Re: Block division

    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");
    }

    }}

  6. #6
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: Block division

    Please edit the post and wrap the code in code tags to make it easier to read.

    its not working
    can you explain what that means? If there are errors, please copy the full text and paste it here.


    Also posted at: http://www.javaprogrammingforums.com...ptography.html
    Last edited by Norm; February 21st, 2014 at 07:14 AM.
    Norm

  7. #7
    Join Date
    Feb 2014
    Posts
    6

    Re: Block division

    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?

  8. #8
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: Block division

    Error appears
    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.

    Please edit your post and wrap your code with code tags:
    [code]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.
    Norm

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured