Results 1 to 6 of 6

Thread: Randomaccessfile using char array

  1. #1
    Join Date
    Dec 2009
    Posts
    263

    Randomaccessfile using char array

    Hello,
    Here is my problem, I am trying to use Randomaccessfile using the char array.
    Code:
    Public class RevisionsRAF 
    {
    	Public static void hand (String [] args) throws IOException
    	{
    		long tlrc = 12;
    		int nb = 4;
    String dir, category;
    		double prices, rates, prixTTC, tax;
    RandomAccessFile ram = new RandomAccessFile("c:\\work\\fichiersTaxes.dat ","rw");
    
    ram.writeChar("LI"); ram.writeDouble(1.45);
    ram.writeChar("DI"); ram.writeDouble(1.60);
    ram.writeChar("CD"); ram.writeDouble(1.75);
    ram.writeChar("DV"); ram.writeDouble(1.85);
    I have the problem with the "LI" and "DL". If you have any solution for this please reply back. Thanks in advance.
    Last edited by TechGate; 27-01-2010 at 11:13 AM.

  2. #2
    Join Date
    Jan 2008
    Posts
    1,521

    Re: Randomaccessfile using char array

    Hi,
    I think you are missing this. readChar can not read "LI", it reads only "L"
    cat [0] = ram.readChar (); cat [1] = ram.readChar ();
    In cat [0] you: "L", and cat [1] you have "I"
    Then you do:
    Scat String = new String (cat);
    So you create a chain that contains "L" + "I" => "LI"
    and then
    System.out.println ( "here" + SCAT);
    hope this will help you.

  3. #3
    Join Date
    Dec 2009
    Posts
    263

    Re: Randomaccessfile using char array

    Hello,
    Thank you for your explanation simple and clear. Same question as in my previous message, how many bytes per character, I have a less idea in this topic, so if you can explain me in more details I can catch the point. You have post it, but I did not understand all the concepts. Thank you for your dedication.

  4. #4
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Randomaccessfile using char array

    Hello,
    Java characters are encoded in Unicode (UTF16 I think) so 16-bit, which makes us so good 2 bytes. By cons I have a little doubt, the method writeChar readChar and do it not convert the charset of the default OS (UTF8 under windaube example), making that are one byte in the file? I take back what I said to convert to UTF8. I have tested. Actually I confused with PrintWriter.println (String), which is in the string format.

  5. #5
    Join Date
    Dec 2009
    Posts
    263

    Re: Randomaccessfile using char array

    Hello,
    Thank you for your reply. So char is good two octets. Besides documenting sun, THERE-there's a way to find a summary table with the size of Write ? I hope I am correct here. Do you know any other site for documentation, where I can find easy documents and learn quicker. This is going to help me, if you have any one, please send me a link.

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

    Re: Randomaccessfile using char array

    Hello,
    Javadoc:
    Character.SIZE: number of bits used to store a character in memory. This value is 16. To convert byte, divide by 8 -> = 2 bytes.
    In the same kind you can do Integer.SIZE, etc. Long.SIZE.
    what I know:
    char = 2
    int = 4
    Long = 8
    If you need any other help with this topic then please do post back.

Similar Threads

  1. Array of char and int
    By Jensen Ackles in forum Software Development
    Replies: 5
    Last Post: 23-03-2010, 09:50 AM
  2. Problem in representing 3 x 3 array of char in c++
    By KAILEY in forum Software Development
    Replies: 5
    Last Post: 20-02-2010, 08:05 PM
  3. Comparing char array in c++
    By MAHAH in forum Software Development
    Replies: 5
    Last Post: 15-02-2010, 08:19 PM
  4. Size of a pointer to an array of char
    By Zool in forum Software Development
    Replies: 3
    Last Post: 14-10-2009, 12:05 PM
  5. How do i clear char array in c++
    By B_Hodge in forum Software Development
    Replies: 3
    Last Post: 16-05-2009, 09:35 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,713,946,034.40361 seconds with 17 queries