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.pswp.cn/news/379468.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/379468.shtml
英文地址,請注明出處:http://en.pswp.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…