Animal; Light; Width; Height; Size // line 1 dog; lamp; 10; 20; 15 // line 2
Acc; Name; Phone; Address; ID; // line 3 Test; Peter; 900234; 10 Le Duan; 5 // line 4
So i would like to store the line 1 and line 3 with variables: animal; light; width; height; size.... I would like to retrieve the data: animal = dog; light = lamp; width = 10; height = 20; size =15..... id = 5; So please help me to slove my problem. Thanks and best regards,
How far have you gotten? It's hard to tell if you're stuck at reading files, parsing text or maybe digging into reflection to set variables. Show us what you have and we can see right where you're stuck.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
[Tran]: 1- It doesn't report the error but still not show on the console.
This is very important - your catch block doesn't do anything. It could be catching an error here, but since there's no code inside the catch block, it does nothing with the error, and then the program continues. This is very bad - it hides the error from the programmer (you).
To fix this you can either (a) put e.printStackTrace() inside the catch block (or some other code which reports the error somehow), or (b) remove the try/catch and just let the exception be thrown. You may need to add some more exceptions to the "throws" clause if you do this.
[Tran]: 2- For now the file have form following: quote: 12:14:16; acc ; name; id; size
The first field is time format (hh:mm:ss)so i cannot use startWith() method , because it is change follow the time. Please suggest me the solution
You could try something like
That assumes that the only lines that start with digits (numbers) are the lines that start with times. If there are also other types of lines with numbers, then you will need something more complex. A regular expression would be a good general solution. That may take some time to understand if you're not familiar with regular expressions, but they're very useful to know about. I don't know if you need to know about them for this problem, but you should learn about them eventually.
Some other notes:
If this is intended to be a constant, you probably want to add "final" to the modifiers here.
Is this on Windows, or some sort of Unix? On Windows you probably want to use \\ rather than /. Java may "correct" this for you in some cases, but in general it's easier to be consistent in the first place - use the separator that's appropriate for your system.
There's no reason for "line" to be declared as part of the class. It's only used within one method, and you don't need to remember any previous value from the last time the method was called. So it's better to just declare the variable within that method, as close as possible to where it's used.
While this works, it's generally a very inefficient way to manipulate Strings. What happen is, it gets converted into something like this:
Every time you use + in a new expression, it creates a new StringBuilder to get the result. It's better (and simpler) to just put these all in one line:
For now, i have 3 fields: 1- formatTime variable (hh:mm:ss); 2- a typeMsg variable is type Message. 3- a byte array with byteArr: (private byte byteArr "030000002f130200000000000800450000800000000001119f7a0a000000e0e02f13c5dac5da006c000000000000030300