java getname_Java文件类字符串getName()方法(带示例)

java getname

文件类字符串getName() (File Class String getName())

  • This method is available in package java.io.File.getName().

    软件包java.io.File.getName()中提供了此方法。

  • This method is used to retrieve or return the filename or directory name and represented by the file path.

    此方法用于检索或返回文件名或目录名,并由文件路径表示。

Syntax:

句法:

    String getName(){
}

Parameter(s):

参数:

We don't pass any object as a parameter in the method of the File.

我们不会在File方法中将任何对象作为参数传递。

Return value:

返回值:

The return type of this method is String that means this method returns the name of file or directory and the name is in string type that's why return type of this method is a string.

该方法的返回类型为String ,这意味着该方法返回文件或目录的名称,并且该名称为字符串类型,这就是该方法的返回类型为字符串的原因。

Java程序演示getName()方法的示例 (Java program to demonstrate example of getName() method)

// import the File class because we will use File class methods
import java.io.File;
//import the Exception class because it may raise an exception 
// when working with files
import java.lang.Exception;
public class GetNameOfFile {
public static void main(String[] args) {
try {
// Specify the path of file and we use double slashes 
// to escape '\' character sequence for windows otherwise 
// it will be considerable as url.
File file = new File("C:\\Users\\computer clinic\\OneDrive\\Articles\\myjava.txt");
// By using getName() we can find the name of the file 
// or directory and file should exists before 
System.out.println("The Name Of The File created is : " + file.getName());
} catch (Exception e) {
System.out.println("An error occurred.");
e.printStackTrace();
}
}
}

Output

输出量

D:\Programs>javac GetNameOfFile.java
D:\Programs>java GetNameOfFile
The Name Of The File created is : C:\Users\computer clinic\OneDrive\Articles\myjava.txt

翻译自: https://www.includehelp.com/java/file-class-string-getname-method-with-example.aspx

java getname

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/379468.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

WF中DependencyObject和DependencyProperty的实现

WF中DependencyObject和DependencyProperty的实现 DependencyProperty的Register和RegisterAttached方法,将DependencyProperty存在IDictionary中完成注册,确保相同name的DependencyProperty在一个ownerType类型中只能有一个。 DependencyObject的GetVal…

hdu2115: I Love This Game

hdu2115: http://acm.hdu.edu.cn/showproblem.php?pid2115题意:输入n组名字和对应的时间(分:秒),要求按时间长度由短到长排序,并输出对应排名,若时间一样,则按名字字典序排序&#…

打开eclipse出现Failed to load the JNI shared library “D:\java\jdk\bin\...\jre\bin\server\jvm.dll”如何解决?

eclipse打开的时候出现Failed to load the JNI shared library “D:\java\jdk\bin…\jre\bin\server\jvm.dll”如何解决?? 如图所示: 即代表你的jdk与eclipse的位数不一样!!! 你可以查看一下eclipse和jd…

Java DataOutputStream writeUTF()方法及示例

DataOutputStream类的writeUTF()方法 (DataOutputStream Class writeUTF() method) writeUTF() method is available in java.io package. writeUTF()方法在java.io包中可用。 writeUTF() method is used to write the given string value to the basic data output stream wit…

2010年世界杯分组

A 南非 墨西哥 乌拉圭 法国 B 阿根廷 南非 韩国 希腊 C 英格兰 美国 阿尔及利亚 斯洛文尼亚 D 德国 澳大利亚 塞尔维亚 加纳 E 荷兰 丹麦 日本 喀麦隆 F 意大利 巴拉圭 新西兰 斯洛伐克 G 巴西 朝鲜 科特迪瓦 葡萄牙 H 西班牙 瑞士 洪都拉斯 智利 转载于:https://www.cnblogs.c…

圆形坠落模拟算法设计

目标:实现一个算法,模拟在一个封闭二维区域,圆形小球朝给定方向坠落的过程,实现二维区域的紧密填充。 像下面这样: 难点,及其简单解决: 1.如何把粒子移动尽可能远? 图中的粒子i&…

Maven详细教学

一、Maven简介 maven:是apache下的一个开源项目,是纯java开发,并且只是用来管理java项目的 依赖管理:就是对jar包的统一管理 可以节省空间 项目一键构建:mvn tomcat:run该代码可以将一个完整的项目运行起来&#xff0…

Java Character.UnicodeBlock of()方法与示例

Character.UnicodeBlock类的()方法 (Character.UnicodeBlock Class of() method) of() method is available in java.lang package. of()方法在java.lang包中可用。 of() method is used to return the Unicode block containing the given parameter value or it returns null…

simpleDBM的B-link树实现

参考的是VLDB2005的这篇论文,做个标记把。/Files/YFYkuner/Concurrency_control_and_recovery_for_balanced_B-link_trees.pdf 转载于:https://www.cnblogs.com/YFYkuner/archive/2009/12/21/1629268.html

网站后台中对html标签的处理

最近做一个CMS&#xff0c;后台中需要使用在线编辑器对新闻进行编辑&#xff0c;然后发表。我用的在线编辑器是CKEditorCKFinder。也许是我为了让CKEditor更本地化吧&#xff0c;改了很多。后来发现在CKEditor中对文字设置字体、颜色、字号大小时文字的<span>标签会出现N…

Java Calendar getActualMaximum()方法与示例

日历类的getActualMaximum()方法 (Calendar Class getActualMaximum() method) getActualMaximum() method is available in java.util package. getActualMaximum()方法在java.util包中可用。 getActualMaximum() method is used to return the maximum value that the given …

软件研发人员考核的十项基本原则(转)

软件研发人员考核的十项基本原则 作者: 任甲林 来源: 万方数据 软件研发人员的考核一直是软件企业管理的难点笔者在长期的研发管理实践与咨询实践中总结了进行软件研发人员考核的一些基本原则。(1) 要体现公司的价值观公司的价值观体现了公司认可什么类型的人员&#xff1f;…

2012.7.24---C#(2)

学习过了C#的基本属性函数后&#xff0c;接下来的学习我觉得比较重要。C#是一种面向对象的语言&#xff0c;下面复习一下面向对象中的一些名词。 类&#xff1a;把一些系列东西&#xff0c;把他们的共同的属性和方法抽象出来&#xff0c;给他起一个名字就是XXX类。类中定义…

汇编语言-001(BYTE、DUP、WORD 、DWORD 、QWORD 、TBYTE 、REAL )

1 : 基础汇编语言展示 .386 .model flat,stdcall .stack 4096 ExitProcess PROTO,dwExitCode:DWORD.code main PROCmov eax,5add eax,6INVOKE ExitProcess,0 main ENDP END main2:基础汇编语言展示增加变量的访问 .386 .model flat,stdcall .stack 4096 ExitProcess PROTO,dw…

<各国地图轮廓app>技术支持

如在app使用过程中遇到任何问题&#xff0c;请与开发者联系caohechunhotmail.com

Java BigDecimal longValueExact()方法与示例

BigDecimal类longValueExact()方法 (BigDecimal Class longValueExact() method) longValueExact() method is available in java.math package. longValueExact()方法在java.math包中可用。 longValueExact() method is used to convert this BigDecimal to an exact long val…

c#中的多线程同步

在处理多线程同步问题的时候&#xff0c;我们一般有临界区&#xff0c;互斥量&#xff0c;信号量和消息机制等几种解决方案&#xff0c;在c#中可以非常方便的使用它们来实现进程的同步。下面我就常用的lock,Monitor和Mutex几种来说明如何实现进程的同步。 lock和Monitor依靠一种…

ffplay SDL_OpenAudio (2 channels, 44100 Hz): WASAPI can‘t initialize audio client“

windows下&#xff1a; ffplay 提示"SDL_OpenAudio (2 channels, 44100 Hz): WASAPI can’t initialize audio client" 添加环境变量&#xff1a;SDL_AUDIODRIVERdirectsound

js 正则表达式,正整数

var ss "3.333";var type /^[0-9]*[1-9][0-9]*$/;var re new RegExp(type);alert(ss.match(re));if (ss.match(re) null) {alert("请输入大于零的整数!");return;} 转载于:https://www.cnblogs.com/lingxzg/archive/2012/08/02/2620543.html

java 根据类名示例化类_Java即时类| EpochSecond()方法的示例

java 根据类名示例化类EpochSecond()方法的即时类 (Instant Class ofEpochSecond() method) Syntax: 句法&#xff1a; public static Instant ofEpochSecond(long sec_val);public static Instant ofEpochSecond(long sec_val, long nanos_adjust);ofEpochSecond() method is…