一起做面試題 遞迴讀取檔案

2021-07-11 19:23:18 字數 422 閱讀 1556

這是一道面試題,要求給定乙個檔案路徑,讀出檔案路徑下所有檔案、資料夾和所有資料夾子檔案。

不多說了看**吧。

class node

public filetree(string path)else

} catch (ioexception e)

}public void addsiblings(nodeparent) throws ioexception

file self=parent.getself();//獲取檔案本身

string siblingnames=self.list();//獲取子檔案和子資料夾

for(string name:siblingnames)

} }}public static void main(string args)

}寫的比較簡陋,湊合看吧

python讀取檔案的面試題

usr bin env python coding utf 8 加中間值 import codecs with open test.txt r as fp txt fp.readlines print txt sum 0for i in txt sum int i 1 print sum 從每一行截...

非常經典的面試題,方案很多,一起交流學習

樓上走到樓下共有10個台階,每一步有3種走法 走1個台階 走2個台階 走3個台階.問可走多少種方案?不妨設有n階台階,既然一次只能走一步或2步或3步,那麼假設現在僅剩下最後一步要走,有三種情況 一 只需要走一步,這時已經走了 n 1 階,走法與走n 1階相同,有f n 1 階走法 二 只需要走兩步,...

一道面試題 檔案拷貝

情景 在面試過程中,求職者被要求寫乙個檔案拷貝函式。問 你是怎樣理解 拷貝 的?答 嗯.就是把檔案的內容複製到新檔案。問 那麼時間戳呢?答 不拷貝。問 目標檔名是否必須相同?答 不必。問 那它的名字 能否一樣?答 這個.不能。問 要不要擔心名字欺騙?比如土耳其 i 注1 答 不要擔心。問 檔案位置是...