6 Replies Latest reply on Mar 16, 2009 8:58 AM by 807588

    File accessing/opening from a network path

    807588
      Hi All,

      Any idea of how to access/open a file which is in the network path.

      For example my network path is \\ingbtcpic6dt415\\Files\\Viswanadh.txt

      How to access Viswanadh.txt..???

      Thanks in advance.

      regards,
      Viswanadh
        • 1. Re: File accessing/opening from a network path
          577611
          There are no special ways to access a file over a network path. For instance you can simply access a network file like this
          File file = new File("\\\\ingbtcpic6dt415\\Files\\Viswanadh.txt");
          • 2. Re: File accessing/opening from a network path
            807588
            Thanks for the reply rksharma.I want a clarification about one package.What is the difference between
            import java.io.*;
            
                and
            
            import java.nio.*;
            package??

            regards,
            Viswanadh
            • 3. Re: File accessing/opening from a network path
              577611
              The IO package deals with Input and Output operations in Java. NIO stands for New I/O and was introduced with JDk1.4 to complement the existing I/O packages. More here.

              Edited by: rksharma on 16 Mar, 2009 2:20 PM
              • 4. Re: File accessing/opening from a network path
                807588
                Thanks rksharma.I have coded instantly something like this.
                import java.io.*;
                
                public class FileFromNetworkDemo{
                public static void main(String args[])
                {
                File local = new File("\\btc6n005\\pstv\\TV52x_DrvPlf\\TV543 DrvPlf\\01 Engineering\\31 Validation\\04 Test Results\\02 Functional Test Results\\NXP_Reference\\Wk908");
                if(local.isDirectory())
                {
                System.out.println("Path is:"+local.getName());
                 File[] files = local.listFiles();
                  for(int i = 0; i < files.length; i++)
                     {
                     System.out.println("File Name is:"+files);
                     }
                }
                else
                {
                System.out.println("No file found in the given network path");
                }
                }
                }
                I am getting the output as the println which is in the else.How far i am correct and How far i am wrong..??
                
                Can you guide me???
                
                Thanks in advance.
                
                regards,
                Viswanadh                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
                • 5. Re: File accessing/opening from a network path
                  577611
                  If "btc6n005" is a machine on a network then the path should be +\\\\btc6n005+. Notice the 4 slashes?
                  • 6. Re: File accessing/opening from a network path
                    807588
                    Thanks for the help sharma.Problem has been solved.

                    Thank you once again.

                    regards,
                    Viswanadh