Find all files in a directory with extension .txt in Python

This question’s answers are a community effort. Edit existing answers to improve this post. It is not currently accepting new answers or interactions. How can I find all the files in a directory having the extension .txt in python? 25 s 25 You can use glob: import glob, os os.chdir(“/mydir”) for file in glob.glob(“*.txt”): print(file) … Read more

How do I create a Java string from the contents of a file?

I’ve been using the idiom below for some time now. And it seems to be the most wide-spread, at least on the sites I’ve visited. Is there a better/different way to read a file into a string in Java? private String readFile(String file) throws IOException { BufferedReader reader = new BufferedReader(new FileReader (file)); String line … Read more