File with extension and without extension
package com.demo;
import java.io.File;
public class StringSample {
static private String name = "namratha.asher";
private static String getNameWithTxtExtension(File file) {
return file.getAbsolutePath()
+ ".txt";
}
private static String getNameWithoutExtension(File file) {
return file.getName();
}
public static void main(String[] args) {
System.out.println("string is "+name.lastIndexOf(".") );
String name = getNameWithTxtExtension(new File("c:/test"));
System.out.println("file with ext "+name);
String nameext = getNameWithoutExtension(new File("c:/test"));
System.out.println("file with out extn "+nameext);
}
}
No comments:
Post a Comment