हिंदी

Write a Program to Assign a Full Path and File Name as Given Below. Using Library Functions, Extract and Output the File Path, File Name and File Extension Separately as Shown. - Computer Applications

Advertisements
Advertisements

प्रश्न

Write a program to assign a full path and file name as given below. Using library functions, extract and output the file path, file name and file extension separately as shown.
Input C: / Users / admin / Pictures / flower.jpg
Output path: C: / Users/admin/Pictures/
File name: flower
Extension: jpg

संक्षेप में उत्तर

उत्तर

import java.io.*;
class fileaddress
{
    String pathname,filename,extensionname,path;
    public static void main ( ) throws IOException
    {
          InputStreamReader IR = new InputStreamReader (System.in);
          BufferedReader br = new BufferedReader (IR);
          System.out.println ("Enter the fullpath with filename and extension :");
          pathname = br.readLine ( );
          if (pathname.startsWith ("\") && pathname.ends With ("."))
          {
               int r = pathname.lostIndexOf("\");
               int s = pathname.indexOf(".");
               filename = pathname.substring (r + 1,s);
               extensionname = pathname.substring (s + 1);
               path = pathname.substring (0,r+1);
         }
         System.out.println ("Path :" + Path);
         System.out.println ("File Name : " + filename)
         System.out.println ("Extension :" + extensionname);
         }}

The variable description is as follows:

S.No. Variable Name Data type Purpose
1. pathname string to store full path name of file
2. filename string to store file name
3. extensionname string to store extension of file
4. path string to store only pathname with file and extension name
5. IR for input stream reader
6. br for buffered reader
7. r int to store position no. of string “/”.
8. s int to store position number of string
shaalaa.com
Usage of Wrapper Classes
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
2013-2014 (March) Set 1
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×