Results 1 to 2 of 2

Thread: How to access

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

    Default How to access

    Hello,

    My requirment is that 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:

    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*102 4));

    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" );
    }

    }

    }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Moderator
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    10,100
    Rep Power
    17

    Default Re: How to access

    Take a look through the forum FAQs and learn how to post code so that it maintains its formatting.

    db
    Why do they call it rush hour when nothing moves? - Robin Williams

Similar Threads

  1. Replies: 0
    Last Post: 01-10-2011, 06:26 AM
  2. Default Access (package access) confusion
    By gauravrajbehl in forum New To Java
    Replies: 1
    Last Post: 11-18-2009, 10:48 AM
  3. Entity - Field-Based Access Vs Property Based Access
    By CatchSandeepVaid in forum Enterprise JavaBeans (EJB)
    Replies: 3
    Last Post: 11-02-2009, 07:18 PM
  4. Method access or field access
    By carderne in forum New To Java
    Replies: 2
    Last Post: 12-06-2008, 06:20 PM
  5. Replies: 1
    Last Post: 08-07-2007, 07:51 AM

Posting Permissions

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