Results 1 to 6 of 6
Thread: array to single char
- 11-04-2010, 12:42 PM #1
Member
- Join Date
- Nov 2010
- Posts
- 5
- Rep Power
- 0
- 11-04-2010, 12:53 PM #2
- 11-04-2010, 01:16 PM #3
Member
- Join Date
- Nov 2010
- Posts
- 5
- Rep Power
- 0
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
- 11-04-2010, 01:42 PM #4
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)
- 11-04-2010, 02:51 PM #5
Member
- Join Date
- Nov 2010
- Posts
- 5
- Rep Power
- 0
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
- 11-04-2010, 02:58 PM #6
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
-
convert byte array into char array
By kgkamaraj in forum New To JavaReplies: 4Last Post: 09-13-2011, 11:32 AM -
create a 2d char array from a 1D string array
By jschmall12 in forum New To JavaReplies: 1Last Post: 04-27-2010, 09:01 PM -
how to store into array.char cannot dereference
By dark_metal in forum New To JavaReplies: 9Last Post: 04-05-2010, 07:40 PM -
array of char
By sinisab in forum New To JavaReplies: 9Last Post: 01-05-2010, 09:48 AM -
Convert Char Array to String Array
By Mayur in forum New To JavaReplies: 8Last Post: 10-12-2009, 11:41 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks