Java.io.File.getPath()方法实例
生活随笔
收集整理的這篇文章主要介紹了
Java.io.File.getPath()方法实例
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
轉載自??Java.io.File.getPath()方法實例
?
java.io.File.getPath()?方法將抽象路徑名到路徑名字符串。為了分離名稱的序列所產生的字符串使用默認名稱分隔符。
聲明
以下是java.io.File.getPath()方法的聲明:
public String getPath() String getPath()參數
-
NA
返回值
該方法返回此抽象路徑名的路徑名字符串的形式。
異常
-
NA
例子
下面的示例演示java.io.File.getPath()方法的用法。
package com.yiibai;import java.io.File;public class FileDemo {public static void main(String[] args) {File f = null;String v;boolean bool = false;try{// create new filef = new File("test.txt");// pathname string from abstract pathnamev = f.getPath();// true if the file path existsbool = f.exists();// if file existsif(bool){// printsSystem.out.print("pathname: "+v);}}catch(Exception e){// if any error occurse.printStackTrace();}} } com.yiibai;import java.io.File;public class FileDemo {public static void main(String[] args) {File f = null;String v;boolean bool = false;try{// create new filef = new File("test.txt");// pathname string from abstract pathnamev = f.getPath();// true if the file path existsbool = f.exists();// if file existsif(bool){// printsSystem.out.print("pathname: "+v);}}catch(Exception e){// if any error occurse.printStackTrace();}} }讓我們編譯和運行上面的程序,這將產生以下結果:
pathname: test.txt: test.txt?
?
總結
以上是生活随笔為你收集整理的Java.io.File.getPath()方法实例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 电脑的配置怎么看?(电脑的的配置怎么看)
- 下一篇: 看电脑的配置怎么看的(看电脑的配置怎么看