471,119 Members | 1,483 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,119 software developers and data experts.

access password protected system using java code

I need to write a java program in which i need to access a computer in my network using IP address but system is password protected.so how can i access a password protected system to fetch a file from specified location and use store in my system?

I got a code from google but its not working...Please help!

import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.net.Authenticator;
import java.net.InetAddress;
import java.net.PasswordAuthentication;
import java.net.URL;

public class Main {
public static void main(String[] argv) throws Exception {
Authenticator.setDefault(new MyAuthenticator());
URL url = new URL("\\test\\abc.doc");
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String str;
while ((str = in.readLine()) != null) {

class MyAuthenticator extends Authenticator {
protected PasswordAuthentication getPasswordAuthentication() {
String promptString = getRequestingPrompt();
String hostname = getRequestingHost();
InetAddress ipaddr = getRequestingSite();
int port = getRequestingPort();

String username = "priyanka";
String password = "wipro_123";
return new PasswordAuthentication(username, password.toCharArray());
Mar 24 '11 #1
0 1392

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by shoby | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.