Results 1 to 7 of 7
  1. #1
    Join Date
    Apr 2012
    Posts
    5
    Rep Power
    0

    Default Who to access other remote machine folder from java program which is in another remot

    According to my requirment:
    I have developed a code which get all the Folders and files path and there size respectivelyfor that particular Remote machine. Now i want to access other remote machine from the same piece of code.

    Or I can say suppose I created one HTML page in which i gave 5 Remote machine name and a submit button.
    So when i checked all the checkbox and submit the button it sgould show all the folder anf file names with size for that oarticular machines
    Here i am pasting my code:
    Java Code:
    import java.io.File;
    import java.io.OutputStreamWriter;
    import java.text.DecimalFormat;
    import java.text.NumberFormat;
    
    
    public class  GetFolderSize
    {
    	long totalsize=0;
    
    	static GetFolderSize fg=new GetFolderSize();
    	public static void main(String args [])
    	{ 
    		
    		try
    		{ 
    			File file = new File("D:/Projects");
    			File[] listOfFiles = file.listFiles();
    	        long size = 0;
    	        
    		for (int i = 0; i < listOfFiles.length; i++)
    		{
    			if(listOfFiles[i].isFile())
    			{
    			    System.out.println("File Names: " + listOfFiles[i].getName());
    			    size = file.length();
    		    }    
    		else if(listOfFiles[i].isDirectory())
    		{
    			 System.out.println("Folder Names:" + listOfFiles[i].getName());
    		}
    			File[] subFiles = file.listFiles();
    
    			for (File file1 : subFiles)
    			{
    				if (file1.isFile())
    				{
    					
    					size =fg.getFileSize(file1);
    			    } 
    				else 
    				{
    			   		
    				}
    			}
    		}
    		
    	    fg.sizecal(size, file);
    		}
    		catch (Exception e)
    		{
    			System.out.print(e.getMessage());
    		}
    	}
    
    		public long getFileSize(File file )
    	  	{ 	
    			long fileSizeByte =0;
    			
    	  	 if(file.isFile())
    	  	 {
    	  		fileSizeByte=file.length();
    	  		fg.sizecal(fileSizeByte,file);
    	  		totalsize=totalsize+fileSizeByte;
    		 }
    	  	 else if(file.isDirectory())
    	  	 {
    	  		fileSizeByte=file.length();
    	  		fg.sizecal(fileSizeByte,file);
    	  		totalsize=totalsize+fileSizeByte;
    	  	 }
    	  	  
    			return totalsize;
    		}
    		
    		public void sizecal(long fileSizeByte,File file)
    		{
    			 DecimalFormat fmt =new DecimalFormat("#.##");
    			  Double fileSizeKB=Double.valueOf(fmt.format(1024));            
    			  Double fileSizeMB=Double.valueOf(fmt.format(1024*1024));            
    			  Double fileSizeGB=Double.valueOf(fmt.format(1024*1024*1024));
    			
    				 if(fileSizeByte>fileSizeGB)
    				  {
    				    System.out.println(file.getAbsolutePath()+": size :"+fileSizeByte/ 103741824+" GB" );
    				  }
    				  else if(fileSizeByte>fileSizeMB)
    				  {
    				    System.out.println(file.getAbsolutePath()+": size :"+fileSizeByte/1048576+" MB" );
    				  }
    				  else if(fileSizeByte>fileSizeKB)
    				  {
    				    System.out.println(file.getAbsolutePath()+": size :"+fileSizeByte/1024+" KB" );
    				  }
    				  else
    				  {
    				    System.out.println(file.getAbsolutePath()+": size :"+fileSizeByte+" bytes" );
    				  }
    			
    		}
    
    	}
    Last edited by Norm; 04-06-2012 at 02:20 PM. Reason: added code tags

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,755
    Rep Power
    25

    Default Re: Who to access other remote machine folder from java program which is in another r

    want to access other remote machine from the same piece of code.
    How do you plan to access the remote machine? Using classes like Socket or URLConnnection?
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Join Date
    Apr 2012
    Posts
    5
    Rep Power
    0

    Default Re: Who to access other remote machine folder from java program which is in another r

    Hi Norm,

    Sorry for late response.
    URL connection will be suitable for my requirment.

    THanks,
    Pallavi

  4. #4
    Join Date
    Apr 2012
    Posts
    5
    Rep Power
    0

    Default Re: Who to access other remote machine folder from java program which is in another r

    And one more thing the remote which i am plaaning to access are not having Java installed.

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,755
    Rep Power
    25

    Default Re: Who to access other remote machine folder from java program which is in another r

    The remote machines will need some software that your program can communicate with. Do you know what that will be?
    Some kind of server to talk to and make requests of.
    If you don't understand my response, don't ignore it, ask a question.

  6. #6
    Join Date
    Apr 2012
    Posts
    5
    Rep Power
    0

    Default Re: Who to access other remote machine folder from java program which is in another r

    Quote Originally Posted by Norm View Post
    The remote machines will need some software that your program can communicate with. Do you know what that will be?
    Some kind of server to talk to and make requests of.
    yes they are connected to server and they make request to rsq38pelgen.

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,755
    Rep Power
    25

    Default Re: Who to access other remote machine folder from java program which is in another r

    Can you explain what software is on the remote machines and how your software will communicate with the remote machines?
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Replies: 10
    Last Post: 02-28-2012, 09:44 PM
  2. Java program to ping remote machine using IP address..?
    By prabhurangan in forum New To Java
    Replies: 19
    Last Post: 11-22-2011, 04:58 PM
  3. Connect to remote Windows machine using JAVA on Linux
    By sumukh_death in forum Networking
    Replies: 6
    Last Post: 09-23-2011, 07:23 PM
  4. connect to remote machine
    By RaSdab in forum New To Java
    Replies: 1
    Last Post: 04-23-2011, 02:30 PM
  5. Access remote machine files
    By blueprats in forum New To Java
    Replies: 16
    Last Post: 02-21-2010, 04:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •