Save upd packets in textfile problem
in
Programming Questions
•
1 year ago
this is a part of my code it receive some udp packets an I want to save that in a text file , but I think something is wrong because it does not work , probably because it receive tha packets gradually and it's not like normal that we have an array of strings already
- void receive(byte[] data, String HOST_IP, int PORT_RX) {
- int j = 0 ;
- while ( j<10 ) {
- if ( data[2*j+2] >= 0 ) {
- String bin2 = str((float)unbinary(binary(data[2*j+3])+binary(data[2*j+2])+binary(data[2*j+1])+binary(data[2*j]))/100);
- String[] words = split(bin2, ' ');
- saveStrings("nou.txt", words);
when I try to print word string it looks like this :
- [Ljava.lang.String;@405cce38
- [Ljava.lang.String;@4058a428
- [Ljava.lang.String;@4056fd98
- [Ljava.lang.String;@40574a58
why it's printing in this strange format?
I also tried this :
- try {
- while ( data != null ) {
- output = createWriter("c:/file.txt");
- output.println("1");
- output.flush();
- output.close();
- print("finish");
- }
- }
- catch (Exception e) {
- println("error:");
- }
- java.lang.reflect.InvocationTargetException
- at java.lang.reflect.Method.invokeNative(Native Method)
- at java.lang.reflect.Method.invoke(Method.java:507)
- at hypermedia.net.UDP.callReceiveHandler(UDP.java:677)
- at hypermedia.net.UDP.listen(UDP.java:574)
- at hypermedia.net.UDP.run(UDP.java:606)
- at java.lang.Thread.run(Thread.java:1019)
- Caused by: java.lang.ArrayIndexOutOfBoundsException
- at changethispackage.beforesubmitting.tothemarket.udp1.udp1.receive(udp1.java:47)
- ... 6 more
- [12-06-14 10:14:15.951 +0000] receive packet <- from /192.168.0.23, port:2026, length: 96
- error:
- error:
- error:
- error:
- error:
- error:
- error:
- error:
1