Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    257
    Rep Power
    0

    Please help me with arrays


    Can I send or receive arrays to the server or from the server?
  2. #2
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,713
    Rep Power
    348
    Look at the ObjectOutputStream and ObjectInputstream classes methods.
  4. #3
  5. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    257
    Rep Power
    0
    Originally Posted by NormR
    Look at the ObjectOutputStream and ObjectInputstream classes methods.
    Where can I find them?
  6. #4
  7. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,713
    Rep Power
    348
    They are documented in the Java API doc:
    http://docs.oracle.com/javase/7/docs/api/
  8. #5
  9. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    257
    Rep Power
    0
    I can't find the technique to use it to send arrays. Please give me a code example.
  10. #6
  11. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,713
    Rep Power
    348
    Use the writeObject() method to write the array and the readObject() method to read it.

    Write a small program that tests the methods before trying to use them in a larger program. Write the array to a disk file and read from that file. Use a cast with the readObject() method to cast the array into the correct type of array.
  12. #7
  13. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    257
    Rep Power
    0
    Originally Posted by NormR
    Use the writeObject() method to write the array and the readObject() method to read it.

    Write a small program that tests the methods before trying to use them in a larger program. Write the array to a disk file and read from that file. Use a cast with the readObject() method to cast the array into the correct type of array.
    Give me an example please. How to send and receive strings from clients?
  14. #8
  15. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,713
    Rep Power
    348
    Use the writeObject() method to write an array
    and the readObject() method to read an array.
    Code:
    String[] aStrArray = ...
    ...
    oos.writeObject(aStrArray); //  write the array
    
    //----------- to read the array
    String[] anArray = (String[])ois.readObject();  // read and cast object to array
  16. #9
  17. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    257
    Rep Power
    0
    Originally Posted by NormR
    Use the writeObject() method to write an array
    and the readObject() method to read an array.
    Code:
    String[] aStrArray = ...
    ...
    oos.writeObject(aStrArray); //  write the array
    
    //----------- to read the array
    String[] anArray = (String[])ois.readObject();  // read and cast object to array
    Can I use:

    Code:
    String[] aStrArray = new String();
  18. #10
  19. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,713
    Rep Power
    348
    Can I use:
    String[] aStrArray = new String();
    What does the compiler say when you use that statement in a java program?
    Does it give an error message?
  20. #11
  21. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    257
    Rep Power
    0
    How to send or receive a string that is not an array?
  22. #12
  23. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,713
    Rep Power
    348
    Use the same code with a different cast:

    Code:
    String aStr = ...
    ...
    oos.writeObject(aStr); //  write the String
    
    //----------- to read the String
    String anotherStr = (String)ois.readObject();  // read and cast object to String
  24. #13
  25. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    257
    Rep Power
    0
    Originally Posted by NormR
    Use the same code with a different cast:

    Code:
    String aStr = ...
    ...
    oos.writeObject(aStr); //  write the String
    
    //----------- to read the String
    String anotherStr = (String)ois.readObject();  // read and cast object to String
    It is not working. Should I import any things?
  26. #14
  27. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,713
    Rep Power
    348
    It is not working.
    Please explain what "not working" means.
    Post the code and the full text of the error messages.
    Post all the output that shows what the code is doing.
  28. #15
  29. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    257
    Rep Power
    0
    Originally Posted by NormR
    Please explain what "not working" means.
    Post the code and the full text of the error messages.
    Post all the output that shows what the code is doing.
    Java said that it cannot find symbol. So?
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo