❶ 怎樣查文件路徑
在文件的快捷方式圖標右擊,然後選擇
查找目標
即可看到文件所在位置!
我的電腦打開默認地址欄上就有文件的路徑!如果沒有,可以打開我的電腦選擇工具里的文件夾選項,然後在文件夾選項里點擊
查看
找到
在地址欄中顯示完整路徑
即可!
❷ java如何判斷文件路徑
package jixutest;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.text.DateFormat;
import java.util.Date;
public class TestERead extends Frame implements ActionListener,ItemListener{
private List list;//用於顯示文件列表
private TextField details;//用於顯示選中的文件(夾)詳細情況
private Panel buttons;//用於放置兩個button
private Button up,close;
private File currentDir;
private FilenameFilter filter;//文件篩選器
private String[] files;//放置文件(夾)名的數組
private DateFormat dateFormatter=DateFormat.getDateTimeInstance(DateFormat.SHORT,DateFormat.SHORT);//日期格式化,注意getDateTimeInstance有兩個念前顫參數,分別表示日期和時間
/*
* 說明:
* DateFormat shortDateFormat =DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
* DateFormat mediumDateFormat =DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
* DateFormat longDateFormat =DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG);
* DateFormat fullDateFormat =DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL);
* 對應的日期時間格式分別如下:
* 9/29/01 8:44 PM
* Sep 29, 2001 8:44:45 PM
* September 29, 2001 8:44:45 PM EDT
* Saturday, September 29, 2001 8:44:45 PM EDT
* */
public TestERead(String directory,FilenameFilter filter){
super("File Lister");//窗口標題
this.filter=filter;//文件篩選器
addWindowListener(new WindowAdapter(){//關閉窗口
public void windowClosing(WindowEvent e){
dispose();
}
});
list=new List(12,false);//一個12行的list表單
list.setFont(new Font("MonoSpaced",Font.PLAIN,14));//設置字體
list.addActionListener(this);//捕捉雙擊滑鼠的行為
list.addItemListener(this);//捕捉悔悔單擊滑鼠的行為(選仔敗中項)
details=new TextField();//顯示文件詳情
details.setFont(new Font("MonoSpaced",Font.PLAIN,12));
details.setEditable(false);//readonly
buttons=new Panel();
buttons.setLayout(new FlowLayout(FlowLayout.RIGHT,15,15));//靠右排列項,間距15 15
buttons.setFont(new Font("SansSerif",Font.BOLD,14));
up=new Button("上一級目錄");
close=new Button("關閉");
up.addActionListener(this);
close.addActionListener(this);
buttons.add(up);
buttons.add(close);
this.add(list,"Center");
this.add(details,"North");
this.add(buttons,"South");
this.setSize(500,300);
listDirectory(directory);//列出指定目錄
}
public void listDirectory(String directory){//此方法作用是列出文件,並不涉及文件的操作
File dir=new File(directory);//創建文件(目錄)對象
if(!dir.isDirectory()){
throw new IllegalArgumentException("FileLister:no such directory");
}
files=dir.list(filter);//列出文件並用filter篩選
java.util.Arrays.sort(files);//排序文件
list.removeAll();//清除此前列出的文件列表
list.add("上一級目錄");
for(int i=0;i<files.length;i++)
list.add(files[i]);//將文件加入到列表框
this.setTitle(directory);
details.setText(directory);
currentDir=dir;
}
public void itemStateChanged(ItemEvent e){ //選中項(單擊)的相應行為,並不涉及雙擊項目
int i=list.getSelectedIndex()-1;//因為我們在列表中的第一項是「上一級目錄」,因此列表的selectedindex要比files的index大一,而我們要獲取files的index,就要相應減去1
if(i<0)
return;
String filename=files[i];
File f=new File(currentDir,filename);
if(!f.exists())
throw new IllegalArgumentException("FileLister:no such file or directory");
String info=filename;
if(f.isDirectory())
info+=File.separator;//如果是目錄就在後面增加一個分隔符,windows下是「\」,Linux下是「/」
info+=" "+f.length()+ " bytes ";
info +=dateFormatter.format(new java.util.Date(f.lastModified()));
if(f.canRead()) info+=" Read";
if(f.canWrite()) info+=" Write";
details.setText(info);
}
public void actionPerformed(ActionEvent e){//雙擊項目、單擊button的行為定義,由此我們也發現,對於列表的雙擊和對按鈕的單擊都屬於ActionEvent
if(e.getSource()==close) this.dispose();//按鈕close的行為定義
else if(e.getSource()==up) {up();}//按鈕up的行為定義
else if(e.getSource()==list) {
int i=list.getSelectedIndex();
if(i==0) up();//如果selectedindex為0,即第一項,就是「上一級目錄」那一項,就調用up()方法
else{
String name=files[i-1];
File f=new File(currentDir,name);
String fullname=f.getAbsolutePath();//取得文件(目錄)的絕對路徑
if(f.isDirectory()) listDirectory(fullname);//如果是目錄,則列出
// else new FileViewer(fullname).setVisible(true);//否則創建一個FileViewer類,即要彈出我們昨天所寫的FileViewer窗口來讀取文件的內容
}
}}
protected void up(){//列出父目錄
String parent=currentDir.getParent();
if(parent==null) return;
listDirectory(parent);//一個遞歸
}
public static void usage(){
System.out.println("Usage: java FileLister [directory_name] "+"[-e file_extension]");
System.exit(0);
}
public static void main(String args[]) throws IOException{
TestERead f;
FilenameFilter filter=null;
String directory=null;
for(int i=0;i<args.length;i++){
if(args[i].equals("-e")){
if(++i>args.length) usage();
final String suffix=args[i];//文件擴展名(-e後接著的輸入參數,因為前面已經有++i)
filter=new FilenameFilter(){//篩選器filter要實現FilenameFliter介面
public boolean accept(File dir,String name){
/*Tests if a specified file should be included in a file list.
* dir - the directory in which the file was found.
* name - the name of the file.
* 就是說,如果文件的擴展名跟我們輸入的一致,則返回true
* 否則判斷文件是否為一個目錄,如果是一個目錄,那麼也返回
* 而其他不符合我們輸入的文件,則不列出
*/
if(name.endsWith(suffix)) return true;
else return (new File(dir,name)).isDirectory();
}
};
}
else {
if(directory!=null) usage();//我們初始化的目錄是null的,如果非null,表明程序有問題,退出
else directory=args[i];//否則將-e前一個參數賦給directory
}
}
if(directory==null) directory=System.getProperty("user.dir");//如果沒有輸入目錄參數,那麼就用用戶當前目錄
f=new TestERead(directory,filter);//創建一個FileLister,這里有兩個參數,一個是目錄,一個是篩選器,這個篩選器就是我們剛才創建的那個,注意這個類中我們並沒有在main方法之外單獨創建一個篩選器方法
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
f.setVisible(true);
}
}
❸ 怎樣查看文件保存路徑
工具材料
電腦 ie瀏覽器
方法如下
1、首悄彎先打開電腦帶悶,在電腦上任意打開一個瀏覽器,如下圖所示,在蠢運彎頁面右上角找到「設置」選項打開。
❹ 路徑是否存在判斷一個路徑是文件還是目錄
可以判斷一個文件或目錄(文件夾)是否存在
import os.path
os.path.exists(path);123
判斷一個文件是否存在
import os.path
os.path.isfile(path);123
判斷一個目錄(文件夾)是否存在
import os.path
os.path.isdir(path);123
判斷一個路徑是文件還是目錄(文件夾)
方法一
方法二
❺ 如何查看文件路徑
右鍵 屬性 在 位置那一欄就是文件路徑
如果是快捷方式的話,
就是 目標那一欄或者起始位置那一欄
❻ c#中如何檢測文件路徑是否存在
stringpath=@"d:A.txt";
if(File.Exists(path))
{
Console.WriteLine("文件存在");
}
❼ 如何判斷一個路徑是目錄還是文件
第十三個findfirstfile尋找文件以及獲得文件的信息
這里舉一個例子吧,列舉e盤第一目錄下的所有文件,包括文件夾,結合findnextfile
#include<windows.h>
#include<stdio.h>
int
main()
{
bool
done=true;
win32_find_data
fd;
handle
hfind
=
findfirstfile("e:\\*.*",
&fd);//第一個參數是路徑名,可以使用通配符,懂dos的人應該知道吧!fd存儲有文件的信息
while
(done)
{
printf("%s\n",fd.cfilename);
done=findnextfile(hfind,
&fd); //返回的值如果為0則沒有文件要尋了
}
return
0;
}
當然也可以直接找一個文件,不使用通配符,但這樣有什麼意義呢?,如findfirstfile("e:\\aaa.txt",&fd);其實這個可以獲取一個文件的信息,如文件是不是隱藏的,或者有沒有隻讀屬性等。
當然通過控制通配符,也可以尋找特定類型的文件,比如我只要找文本文件,那麼就是這個語句findfirstfile("e:\\*.txt",&fd);就行了,關鍵看你自己靈活運用。
前面說過fd里存儲有文件的信息,那怎麼根據fd裡面的成員判斷這個文件的屬性,文件是否隱藏,是不是文件夾。
fd里的dwfileattributes存儲有文件的信息,如判斷是否為文件夾,只要把這個變數和file_attribute_directory進行按位與運算,如果為1的話,表明為文夾件,如if(fd.dwfileattributes&file_attribute_directory==1)
printf("%s是文件夾\n",fd.cfilename);
其它判斷也是一樣,現在給出文件的屬性(常用幾個):file_attribute_hidden(隱藏)
file_attribute_readonly(只讀)file_attribute_system(系統)
第十四個findnextfile尋找文件
參照findfirstfile函數的例子!
❽ java 如何判斷文件路徑是否存在
exists
public boolean exists()測試此抽象路徑名表示的文件或目錄是否存在回。
返回:
當且僅當答此抽象路徑名表示的文件或目錄存在時,返回 true;否則返回 false
isFile
public boolean isFile()測試此抽象路徑名表示的文件是否是一個標准文件。如果該文件不是一個目錄,並且滿足其他與系統有關的標准,那麼該文件是標准 文件。由 Java 應用程序創建的所有非目錄文件一定是標准文件。
返回:
當且僅當此抽象路徑名表示的文件存在且 是一個標准文件時,返回 true;否則返回 false