团队,我试图从目录中获取所有路径,并将所有目录和文件与日期一起保存在txt文件中。
现在,我使用file.getAbsolutePath()获取所有目录和文件,但是只写了一些路径。
File directory = new File(directoryName);
File[] fList = directory.listFiles();
String yourDesktopPath = System.getProperty("user.home") + "\\Desktop\\";
PrintWriter writer = new PrintWriter(yourDesktopPath+"the-file-name.txt", "UTF-8");
try {
for (File file : fList){
if (file.isFile()){
System.out.println(file.getAbsolutePath());
writer.write(file.getAbsolutePath());
} else if (file.isDirectory()){
listFilesAndFilesSubDirectories(file.getAbsolutePath());
}
}
writer.flush();
} finally {
writer.close();
}
答案 0 :(得分:0)
您可以简单地使用import ectd
from ectd import convert
from flask import Flask, request
from flask_restful import Resource, Api
#from flask.views import MethodView
app = Flask(__name__)
api = Api(app)
class ectdtext(Resource):
def get(self, result):
return {'data': ectd.convert(result)}
#api.add_resource(ectdtext, '/ectd/<result>')
#categorie
@app.route('/', defaults={'path': ''})
@app.route('/<path:path>')
def get_dir(path):
categories = convert(path)
return categories
#@app.route('/get_dir/<path>')
#def get_dir(path):
# return path
if __name__ == '__main__':
app.run(host="0.0.0.0", port=5000)
,它将为您执行递归循环,您可以像这样使用它:
java.nio.file.Files
答案 1 :(得分:0)
new PrintWriter(yourDesktopPath+"the-file-name.txt", "UTF-8");
会截断该文件,并删除您先前写入该文件的所有内容。
您需要附加到您的文件。 FileOutputStream具有a constructor,可让您指定它:
PrintWriter writer = new PrintWriter(
new BufferedWriter(
new OutputStreamWriter(
new FileOutputStream(yourDesktopPath + "the-file-name.txt", true),
StandardCharsets.UTF_8));