欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

如何通過(guò)java獲取文件名和擴(kuò)展名

 更新時(shí)間:2020年01月20日 14:43:35   作者:慕塵  
這篇文章主要介紹了如何通過(guò)java獲取文件名和擴(kuò)展名,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下

這篇文章主要介紹了如何通過(guò)java獲取文件名和擴(kuò)展名,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下

如:文件filePath = "E:\\test\\test.dxf"

1.獲取文件名

eg:獲取 test.dxf

通過(guò)file對(duì)象

import java.io.File;

public class test {
  public static void main(String[] args) {

    String filePath = "E:\\test\\test.dxf";
    File tmpFile=new File(filePath);
    String fileName=tmpFile.getName();
    System.out.println(fileName);
  }
}

使用split

public class test {
  public static void main(String[] args) {

    String filePath = "E:\\test\\test.dxf";
    //帶擴(kuò)展名的文件名
    String temp[] = filePath.split("\\\\");
    String fileName = temp[temp.length - 1];
    System.out.println(fileName);
  }
}

使用substring

public class test {
  public static void main(String[] args) {

    String filePath = "E:\\test\\test.dxf";
    String fileName = filePath.substring(filePath.lastIndexOf("\\")+1);
    System.out.println(fileName);
  }
}

2.獲取不帶擴(kuò)展名的文件名

eg:獲取 test

使用substring

public class test {
  public static void main(String[] args) {

    String filePath = "E:\\test\\test.dxf";
    String fileName = filePath.substring(filePath.lastIndexOf("\\")+1);
    String name = fileName.substring(0,fileName.lastIndexOf("."));
    System.out.println(name);
  }
}


3.擴(kuò)展名

eg:獲取 dxf

使用substring

public class test {
  public static void main(String[] args) {

    String filePath = "E:\\test\\test.dxf";
    String fileName = filePath.substring(filePath.lastIndexOf("\\")+1);
    String name = fileName.substring(filePath.lastIndexOf(".")+1);
    System.out.println(name);
  }
}

public class test {
  public static void main(String[] args) {

    String filePath = "E:\\test\\test.dxf";
    String fileName = filePath.substring(filePath.lastIndexOf("\\")+1);
    String[] strArray = fileName.split("\\.");
    int suffixIndex = strArray.length -1;
    System.out.println(strArray[suffixIndex]);
  }
}

public class test {
  public static void main(String[] args) {

    String filePath = "E:\\test\\test.dxf";
    String fileName = filePath.substring(filePath.lastIndexOf("\\")+1);
    System.out.println(fileName);
    String extension=fileName.substring(fileName.lastIndexOf(".")+1,fileName.length());
    System.out.println(extension);
  }
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • SpringBoot @NotBlank錯(cuò)誤的解決方案

    SpringBoot @NotBlank錯(cuò)誤的解決方案

    這篇文章主要介紹了SpringBoot @NotBlank錯(cuò)誤的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-08-08
  • SpringBoot實(shí)現(xiàn)連接nacos并支持多環(huán)境部署

    SpringBoot實(shí)現(xiàn)連接nacos并支持多環(huán)境部署

    這篇文章主要介紹了SpringBoot實(shí)現(xiàn)連接nacos并支持多環(huán)境部署方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-06-06
  • SpringBoot中的自定義Starter解讀

    SpringBoot中的自定義Starter解讀

    這篇文章主要介紹了SpringBoot中的自定義Starter解讀,啟動(dòng)器模塊其實(shí)是一個(gè)空的jar文件,里面沒(méi)有什么類、接口,僅僅是提供輔助性依賴管理,這些依賴可能用于自動(dòng)裝配或者其他類庫(kù),需要的朋友可以參考下
    2023-12-12
  • Spring?Cloud?Ribbon?中的?7?種負(fù)載均衡策略的實(shí)現(xiàn)方法

    Spring?Cloud?Ribbon?中的?7?種負(fù)載均衡策略的實(shí)現(xiàn)方法

    Ribbon?內(nèi)置了?7?種負(fù)載均衡策略:輪詢策略、權(quán)重策略、隨機(jī)策略、最小連接數(shù)策略、重試策略、可用性敏感策略、區(qū)域性敏感策略,并且用戶可以通過(guò)繼承?RoundRibbonRule?來(lái)實(shí)現(xiàn)自定義負(fù)載均衡策略,對(duì)Spring?Cloud?Ribbon負(fù)載均衡策略相關(guān)知識(shí)感興趣的朋友一起看看吧
    2022-03-03
  • Java基礎(chǔ)-Java變量的聲明和作用域

    Java基礎(chǔ)-Java變量的聲明和作用域

    這篇文章主要介紹了Java變量的聲明和作用域,變量其實(shí)就是內(nèi)存中的一個(gè)存儲(chǔ)空間,用來(lái)存儲(chǔ)數(shù)據(jù),具體的相關(guān)內(nèi)容,需要的小伙伴可以參考下面文章內(nèi)容
    2022-01-01
  • Springboot訪問(wèn)html頁(yè)面的教程詳解

    Springboot訪問(wèn)html頁(yè)面的教程詳解

    這篇文章主要介紹了Springboot訪問(wèn)html頁(yè)面的教程,本文圖文并茂給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2018-03-03
  • Eclipse+Java+Swing+Mysql實(shí)現(xiàn)工資管理系統(tǒng)

    Eclipse+Java+Swing+Mysql實(shí)現(xiàn)工資管理系統(tǒng)

    這篇文章主要介紹了Eclipse+Java+Swing+Mysql實(shí)現(xiàn)工資管理系統(tǒng),對(duì)正在工作或者學(xué)習(xí)的你有一定的參考價(jià)值,需要的朋友可以參考一下
    2022-01-01
  • 利用hadoop查詢兩兩之間有共同好友及他倆的共同好友都是誰(shuí)

    利用hadoop查詢兩兩之間有共同好友及他倆的共同好友都是誰(shuí)

    一想到要實(shí)現(xiàn)求共同好友的功能,很多人都會(huì)想到redis來(lái)實(shí)現(xiàn)。但是redis存儲(chǔ)和數(shù)據(jù)和計(jì)算時(shí)需要耗費(fèi)較多的內(nèi)存資源。所以文本將介紹另一種方法,即利用Hadoop中的MapReduce來(lái)實(shí)現(xiàn),感興趣的可以了解一下
    2022-01-01
  • Vue3源碼解讀effectScope API及實(shí)現(xiàn)原理

    Vue3源碼解讀effectScope API及實(shí)現(xiàn)原理

    這篇文章主要為大家介紹了Vue3源碼解讀effectScope API及實(shí)現(xiàn)原理,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-03-03
  • Springboot整合GateWay+Nacos實(shí)現(xiàn)動(dòng)態(tài)路由

    Springboot整合GateWay+Nacos實(shí)現(xiàn)動(dòng)態(tài)路由

    本文主要介紹了Springboot整合GateWay+Nacos實(shí)現(xiàn)動(dòng)態(tài)路由,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2024-08-08

最新評(píng)論