943,640 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 1693
  • Java RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Dec 16th, 2008
0

Re: help me to read a file from another machine in the network.

Now to connect via a Proxy **I think** you need to use the following method while opening the URL Connection using this "openConnection()" method of the URL class.

It takes an object of the Proxy class as an argument.

To construct the Proxy using the Proxy(Proxy(ProxyType, SocketAddress)) constructor itself you will need two items, First is the Proxy type, I am guessing yours is an HTTP proxy server so use Proxy.Type.HTTP as the first argument.
Next you will need a SocketAddress, the SocketAddress class is itself abstract so you will need to use the InetSocketAddress class which is its concrete sub class. Using InetSocketAddress(String hostname, int port) create an object of the InetSocketAddress of your Proxy Server (using the host name and port on which your proxy is running).

So that **should** do the job of getting past your Proxy.
Last edited by stephen84s; Dec 16th, 2008 at 7:33 am.
Featured Poster
Reputation Points: 653
Solved Threads: 151
Nearly a Posting Virtuoso
stephen84s is offline Offline
1,316 posts
since Jul 2007
Dec 16th, 2008
0

Re: help me to read a file from another machine in the network.

A proxy server is a server that services the requests of its clients by forwarding requests to other servers and acts as a gateway.

Ask your networking admin. about ip address of your proxy server ? :-)
Reputation Points: 9
Solved Threads: 2
Light Poster
AlbertPi is offline Offline
33 posts
since Nov 2008
Dec 17th, 2008
0

Re: help me to read a file from another machine in the network.

Using this code the file can be uploaded to the server

Java Syntax (Toggle Plain Text)
  1. <%@ page import="java.io.*" %>
  2.  
  3. <%
  4. String contentType = request.getContentType();
  5. System.out.println("Content type is :: " +contentType);
  6. if ((contentType != null) && (contentType.indexOf("multipart/form-data") >= 0)) {
  7. DataInputStream in = new DataInputStream(request.getInputStream());
  8. int formDataLength = request.getContentLength();
  9.  
  10. byte dataBytes[] = new byte[formDataLength];
  11. int byteRead = 0;
  12. int totalBytesRead = 0;
  13. while (totalBytesRead < formDataLength) {
  14. byteRead = in.read(dataBytes, totalBytesRead, formDataLength);
  15. totalBytesRead += byteRead;
  16. }
  17.  
  18.  
  19. String file = new String(dataBytes);
  20. String saveFile = file.substring(file.indexOf("filename=\"") + 10);
  21. //out.print("FileName:" + saveFile.toString());
  22. saveFile = saveFile.substring(0, saveFile.indexOf("\n"));
  23. //out.print("FileName:" + saveFile.toString());
  24. saveFile = saveFile.substring(saveFile.lastIndexOf("\\") + 1,saveFile.indexOf("\""));
  25. //out.print("FileName:" + saveFile.toString());
  26.  
  27. //out.print(dataBytes);
  28.  
  29. int lastIndex = contentType.lastIndexOf("=");
  30. String boundary = contentType.substring(lastIndex + 1,contentType.length());
  31. //out.println(boundary);
  32. int pos;
  33. pos = file.indexOf("filename=\"");
  34.  
  35. pos = file.indexOf("\n", pos) + 1;
  36.  
  37. pos = file.indexOf("\n", pos) + 1;
  38.  
  39. pos = file.indexOf("\n", pos) + 1;
  40.  
  41.  
  42. int boundaryLocation = file.indexOf(boundary, pos) - 4;
  43. int startPos = ((file.substring(0, pos)).getBytes()).length;
  44. int endPos = ((file.substring(0, boundaryLocation)).getBytes()).length;
  45.  
  46. out.println(boundaryLocation+"pppp"+file.length()+"ooooooooooooo"+(endPos-startPos)+"kkkkk");
  47.  
  48. saveFile = "/usr/programs/apache-tomcat-6.0.16/webapps/Pinnacle/hr_photoGallery/" + saveFile;
  49. FileOutputStream fileOut = new FileOutputStream(saveFile);
  50.  
  51.  
  52. //fileOut.write(dataBytes);
  53. fileOut.write(dataBytes, startPos, file.length());
  54. fileOut.flush();
  55. fileOut.close();
  56.  
  57. out.println("File saved as " +saveFile);
  58.  
  59. }
  60. %>
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
ajithraj is offline Offline
71 posts
since Jan 2008
Dec 17th, 2008
0

Re: help me to read a file from another machine in the network.

See the comments on this code here:

http://www.daniweb.com/forums/thread162658.html
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: a beginner in java needs help
Next Thread in Java Forum Timeline: Intranet aplication





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC