Java文件類字符串getAbsolutePath()方法(帶示例)

文件類字符串getAbsolutePath() (File Class String getAbsolutePath())

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

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

  • This method is used to return the absolute path of the file object (i.e absolute path is the complete path like this c:\\ Articles\\myjava.txt) if filepath is absolute then it retrieve the complete path of the file object.

    如果filepath是絕對路徑,則此方法用于返回文件對象的絕對路徑(即,絕對路徑是諸如c:\\ Articles \\ myjava.txt這樣的完整路徑),然后它將檢索文件對象的完整路徑。

  • The return type of this method is String so it returns the absolute path from the root in a string form.

    此方法的返回類型為String,因此它以字符串形式返回從根開始的絕對路徑。

  • In this method, if we don’t give an absolute path in the file object then also it will return the absolute path of file object where your file exists.

    在這種方法中,如果我們沒有在文件對象中給出絕對路徑,那么它將返回文件所在的文件對象的絕對路徑。

  • This method may raise an exception( i.e. Security Exception) if the desired value cannot be accessed.

    如果無法訪問所需的值,則此方法可能引發異常(即Security Exception)。

Syntax:

句法:

    String getAbsolutePath(){
}

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 so it returns the complete path of the file object as a String.

該方法的返回類型為String,因此它以String形式返回文件對象的完整路徑。

Java程序演示getAbsolutePath()方法的示例 (Java program to demonstrate example of getAbsolutePath() 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 GetAbsolutePath {
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 file1 = new File("C:\\Users\\computer clinic\\OneDrive\\Articles\\myjava.txt");
File file2 = new File("java.txt");
// By using getAbsolutePath() return the complete 
// path(whatever you have given in the file object) of the 
// file object because in the file1 object we already given 
// absolute path 
// [C:\\Users\\computer clinic\\OneDrive\\Articles\\myjava.txt]
String abs_path1 = file1.getAbsolutePath();
// Display absolute path of the file object if given path is absolute.
System.out.println("The path of the file 1 if given path is absolute :" + " " + abs_path1);
// By using getAbsolutePath() return the complete path of the File 
// object even we have not given full path or absolute path is 
// not given [i.e.(java.txt) so it return the whole path 
// with filename where file exists ]
String abs_path2 = file2.getAbsolutePath();
// Display absolute path of the file object if given path is not absolute.
System.out.println("The path of the file2 if given path is not absolute :" + " " + abs_path2);
} catch (Exception e) {
System.out.println("An error occurred.");
e.printStackTrace();
}
}
}

Output

輸出量

D:\Programs>javac GetAbsolutePath.java
D:\Programs>java GetAbsolutePath
The path of the file 1 if given path is absolute : C:\Users\computer clinic\OneDrive\myjava.txt
The path of the file2 if given path is not absolute : D:\Programs\java.txt

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

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/380139.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/380139.shtml
英文地址,請注明出處:http://en.pswp.cn/news/380139.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

遠控免殺專題(15)-DKMC免殺

0x01 免殺能力一覽表 幾點說明: 1、上表中標識 √ 說明相應殺毒軟件未檢測出病毒,也就是代表了Bypass。 2、為了更好的對比效果,大部分測試payload均使用msf的windows/meterperter/reverse_tcp模塊生成。 3、由于本機測試時只是安裝了360全…

面向對象(靜態成員內部類的調用)

class beyond{public static void main(String []args){//外部類名.內部類名 對象名 外部類名.內部類對象(new 內部類名)/*Outer.Inner yy Outer.new Inner(); 類里面有個非靜態方法,需要new創建Inner對象;正常的形式是這樣的,但是我們習慣將new放在前…

SQL——以面向集合的思維方式來思考

本文來自:http://www.ituring.com.cn/article/details/472 為了以有趣的方式更好地幫助你形成面向集合的思維方式,我將給出自己最喜歡的游戲之一——集合。你可以在線玩這個游戲,網址是www.setgame.com/puzzle/set.htm,每天都會貼…

轉載: 統計圖控件NetCharting 和ZedGraph的比較

原文出處:http://hi.baidu.com/goga/blog/item/07b3024f61b8cd35aec3ab47.html最近考察了幾個統計圖表控件包,開源的有ZedGraph,Nplot等,但是相比之下還是ZedGraph強大,方便一些,其他的感覺還是半成品。收費…

【匯編語言】狀態標志符(CF/OF/SF/ZF)在運算(ADD/SUB/ADC/SBB)過程中的響應變化

目錄各類運算時狀態標志的響應變化標志符在各種ADD運算下的響應情況標志符在各種SUB運算下的響應情況借助標志符實現多位數之間運算ADC(add with carry)帶進位加法指令SBB(subtract with borrow)帶借位減法指令各類運算時狀態標志的響應變化 標志符具體含義CF(Carr…

Java集合unmodifiableSortedSet()方法(帶示例)

集合類unmodifiableSortedSet()方法 (Collections Class unmodifiableSortedSet() method) unmodifiableSortedSet() method is available in java.util package. unmodifiableSortedSet()方法在java.util包中可用。 unmodifiableSortedSet() method is used to get a non-modi…

遠控免殺專題(16)-Unicorn免殺

0x01 免殺能力一覽表 幾點說明: 1、上表中標識 √ 說明相應殺毒軟件未檢測出病毒,也就是代表了Bypass。 2、為了更好的對比效果,大部分測試payload均使用msf的windows/meterperter/reverse_tcp模塊生成。 3、由于本機測試時只是安裝了360全…

面向對象(匿名內部類在開發中的應用)

匿名內部類在開發中的應用 public class test1_NoNameInner {public static void main(String[] args) {PersonDemo yy new PersonDemo();//yy.method(new Student());yy.method(new Person() {public void show(){System.out.println("show");}});//匿名內部類當作…

【匯編語言】乘法(MUL/IMUL)

乘法(MUL/IMUL) 目錄乘法(MUL/IMUL)IMUL(signed multiply)有符號數乘法MUL(unsigned multiply)無符號數乘法麻!屬實是被這個有符號乘法給整麻了,教材就一行例子直接不解釋了,關于標志位溢出的一…

【轉】MFC學習總結

HBRUSH CAboutDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { if ((pWnd->GetDlgCtrlID() IDC_EDIT1) && (nCtlColor CTLCOLOR_EDIT)) {   COLORREF clr RGB(255,0,0);   pDC->SetTextColor(clr);  //設置紅色的文本   clr RGB(0,0,0…

NHibernate初學體驗進階篇

在上篇《NHibernate初學體檢記》中&#xff0c;我參照NHibernate官方快速指南寫了兩個示例項目&#xff0c;在示例2的源碼中充斥了如下類似的代碼&#xff1a;<?XML:NAMESPACE PREFIX O />Configuration cfg new Configuration(); cfg.AddAssembly("…

eclipse快捷鍵

Java開發工具(Eclipse的視窗和視圖概述) A:視窗 每一個基本的窗體被稱為視窗 PackageExplorer 顯示項目結構&#xff0c;包&#xff0c;類&#xff0c;及資源Outline 顯示類的結構&#xff0c;方便查找&#xff0c;識別&#xff0c;修改Console 程序運行的結果在該窗口顯示Hie…

【匯編語言】除法(DIV/IDIV)

除法&#xff08;DIV/IDIV&#xff09; 目錄除法&#xff08;DIV/IDIV&#xff09;DIV(unsigned divide)無符號數除法IDIV(signed divide)有符號數除法DIV(unsigned divide)無符號數除法 格式&#xff1a;DIV SRC 操作&#xff1a; SRCSRCSRC為字節時&#xff0c;(AL)←(AX)/…

java 方法 示例_Java集合syncedSortedSet()方法與示例

java 方法 示例集合類SynchronizedSortedSet()方法 (Collections Class synchronizedSortedSet() method) synchronizedSortedSet() method is available in java.util package. java.util軟件包中提供了sharedSortedSet ()方法 。 synchronizedSortedSet() method is used to …

遠控免殺專題(17)-Python-Rootkit免殺

免殺能力一覽表 幾點說明&#xff1a; 1、上表中標識 √ 說明相應殺毒軟件未檢測出病毒&#xff0c;也就是代表了Bypass。 2、為了更好的對比效果&#xff0c;大部分測試payload均使用msf的windows/meterperter/reverse_tcp模塊生成。 3、由于本機測試時只是安裝了360全家桶…

項目管理軟件應用淺析(轉)

項目管理是在一定的約束條件下&#xff0c;以高效率地實現項目業主的目標為目的&#xff0c;以項目經理個人負責制為基礎和以項目為獨立實體進行經濟核算&#xff0c;并按照項目內在的邏輯規律進行有效的計劃、組織、協調、控制的系統管理活動。項目管理的核心技術是網絡計劃技…

斜視角的討論(轉)

http://school.ogdev.net/listshow.asp?page4&typeid0&categoryid5&id0&ListType2 目 錄 1.1 地圖和地表 1.2 斜視角游戲中的視角 1.3 Tile圖片的拼接 1.4 不同地表間的過渡 1.5 地圖數據結構的定義 --------------------------------------------------…

計算機網絡(湖科大教書匠)

計算機網絡&#xff08;湖科大教書匠&#xff09; 本文檔為教學視頻【計算機網絡微課堂&#xff08;有字幕無背景音樂版&#xff09;_嗶哩嗶哩_bilibili】的摘錄 目錄計算機網絡&#xff08;湖科大教書匠&#xff09;一、緒論1.2 因特網概述1.2.1 網絡、互連網&#xff08;互聯…

經緯度

題目描述 給定地球的兩個經緯度坐標&#xff0c;問這兩個點的直線距離。假設地球為球體&#xff0c;半徑為6371009米。 輸入描述: 第一行一個整數T表示數據組數。 接下來n行&#xff0c;每行四個數lat1, lng1, lat2, lng2分別表示兩個點的經緯度。 正數表示北緯和東經。 …

遠控免殺專題(18)-ASWCrypter免殺

免殺能力一覽表 幾點說明&#xff1a; 1、上表中標識 √ 說明相應殺毒軟件未檢測出病毒&#xff0c;也就是代表了Bypass。 2、為了更好的對比效果&#xff0c;大部分測試payload均使用msf的windows/meterperter/reverse_tcp模塊生成。 3、由于本機測試時只是安裝了360全家桶…