首页
/
每日頭條
/
科技
/
查看文件路徑
查看文件路徑
更新时间:2025-12-11 04:11:25

  maven工程的文件路徑

  查看文件路徑(各種文件路徑)(1)

  需求:讀取 player.txt,輸出到控制台錯誤過程: 1)File file =new File (“路徑”) 這個裡面的路徑,(maven 工程);如果文件是放在 maven工程下的 resources 目錄下,取得路徑的方式

  查看文件路徑(各種文件路徑)(2)

  右鍵 需要訪問的文件

  查看文件路徑(各種文件路徑)(3)

  idea 2019.3之後,出現三種路徑

  Absolute Path:文件的絕對路徑,即:文件在磁盤上的物理位置Content Root Path:文件的上下文路徑

  Source Root Path:資源的訪問路徑,适用于 圖片,等一些靜态資源

  file 文件裡的括号 寫絕對路徑是可以的,但是這個一旦 部署到服務器之後,會有問題,因為路徑改變了

  查看文件路徑(各種文件路徑)(4)

  如果遇到 類似的找不到指定的文件

  解決過程: 依次嘗試 1) File file=new File(/players.txt 2)Source Root Path 》 players.txt * 無效* 3)

  Content Root Path: src/main/resources/players.txt 有效

  總結 1)先試 Content Root Path 2)再試 Source Root Path 3)再試 加一個 / 的

  ,

Comments
Welcome to tft每日頭條 comments! Please keep conversations courteous and on-topic. To fosterproductive and respectful conversations, you may see comments from our Community Managers.
Sign up to post
Sort by
Show More Comments
Copyright 2023-2025 - www.tftnews.com All Rights Reserved