Results 1 to 6 of 6
  1. #1
    rfviki is offline Member
    Join Date
    Nov 2010
    Posts
    5
    Rep Power
    0

    Default array to single char

    Hi I have an array for example v[0]=1 v[1]=2 v[2]=3
    How can I join it into a single number in a array indice to be like x[0]=123

    Tanks for any help
    :)

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,985
    Rep Power
    9

    Default

    Quote Originally Posted by rfviki View Post
    Tanks for any help
    You are going to give us a tank if we help you? Awesome.

    But what have you tried? What do you think you should do? What worked, what didn't work? How didn't it work? Be specific.

  3. #3
    rfviki is offline Member
    Join Date
    Nov 2010
    Posts
    5
    Rep Power
    0

    Default

    Hello,
    I am reading a text file that contains numbers for example 2 5 8 20 21
    each number is separated by a space
    that number should be stored in a array.
    Reading a file with v[i]= file.read() except for the space
    everthing works fine for numbers that have a single digit like 2 or 5 or 8
    new array after file.read() will be v[0]=2 v[1]=5 and v[3]=8
    The problem is that i need that 20 that is the next number be stored in v[4]
    Now file.read() gets a 2 and next gets a 0 that must be joined to be a 20 in arrar v[4]

    In the end I need that the text file that contains 2 5 8 20 21 would be stored in the v[0]=2 v[1]=5 v[3]=8 v[4]=20 v[21]=21 to be writted in a binary file using FileOutputStream

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,985
    Rep Power
    9

    Default

    I'm not sure what file.read() is, but it's almost definitely not what you want to be using.

    Give this a careful read-through: Lesson: Basic I/O (The Java™ Tutorials > Essential Classes)

  5. #5
    rfviki is offline Member
    Join Date
    Nov 2010
    Posts
    5
    Rep Power
    0

    Default

    My problem is not the fileI/O that part is working fine
    The only question is how can I pass two elements that are in array index i and i+1 to a single one

    like this
    v[0]=2 and v[1]=1

    2 and 1 must be joined to be 21

    The final objective is

    x[0]=21

  6. #6
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,985
    Rep Power
    9

    Default

    Wrong. Your problem is that you're reading in one character at a time, when you want to read in one word at a time.

    If you don't feel like reading the tutorials, that's fine, but don't expect us to work around your refusal to address the actual problem.

    If you insist that your "problem" is in copying the array indices to a single array index, create an SSCCE that demonstrates exactly what you're trying to do, without any of the extra file IO stuff. Take a guess at it, at least.

Similar Threads

  1. convert byte array into char array
    By kgkamaraj in forum New To Java
    Replies: 4
    Last Post: 09-13-2011, 11:32 AM
  2. create a 2d char array from a 1D string array
    By jschmall12 in forum New To Java
    Replies: 1
    Last Post: 04-27-2010, 09:01 PM
  3. how to store into array.char cannot dereference
    By dark_metal in forum New To Java
    Replies: 9
    Last Post: 04-05-2010, 07:40 PM
  4. array of char
    By sinisab in forum New To Java
    Replies: 9
    Last Post: 01-05-2010, 09:48 AM
  5. Convert Char Array to String Array
    By Mayur in forum New To Java
    Replies: 8
    Last Post: 10-12-2009, 11:41 AM

Posting Permissions

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