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

Reply

Join Date: Jul 2007
Posts: 1,175
Reputation: stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light 
Solved Threads: 125
Featured Poster
stephen84s's Avatar
stephen84s stephen84s is offline Offline
Veteran Poster

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

 
0
  #11
Dec 16th, 2008
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.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."

"How to ask questions the smart way ?"
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 33
Reputation: AlbertPi is an unknown quantity at this point 
Solved Threads: 2
AlbertPi AlbertPi is offline Offline
Light Poster

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

 
0
  #12
Dec 16th, 2008
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 ? :-)
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 71
Reputation: ajithraj is an unknown quantity at this point 
Solved Threads: 1
ajithraj ajithraj is offline Offline
Junior Poster in Training

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

 
0
  #13
Dec 17th, 2008
Using this code the file can be uploaded to the server

  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. %>
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,355
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 252
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

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

 
0
  #14
Dec 17th, 2008
See the comments on this code here:

http://www.daniweb.com/forums/thread162658.html
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC