Snippets tagged “file”
11 snippets use this tag.
- Alternative to file_get_contents?PHP
file_get_contents() is a built-in PHP function that is commonly used to read the contents of a file into a string.
- Getting the filenames of all files in a folderJava
To get the filenames of all files in a folder in Java, you can use the File class and its list method.
- How do I check if a file exists in Java?Java
To check if a file exists in Java, you can use the exists method of the File class from the java.io package. This method returns true if the file exists, and false if it doesn't. Here's an example of how you can use this method:
- How do I get the file extension of a file in Java?Java
To get the file extension of a file in Java, you can use the File class and its getName() method to get the file name, and then use the substring() method of the String class to extract the extension from the file name.
- How do I get the file name from a String containing the Absolute file path?Java
To get the file name from a String containing the absolute file path in Java, you can use the following methods:
- How do I get the full path of the current file's directory?Python
You can use the os module to get the full path of the current file's directory.
- How to read all files in a folder from Java?Java
To read all the files in a folder from Java, you can use the File class from the java.io package to list all the files in a directory. Here's an example of how you can do this:
- How to read file from relative path in Java project? java.io.File cannot find the path specifiedJava
To read a file from a relative path in a Java project, you can use the File class from the java.io package and specify the relative path to the file.
- How to retrieve a module's path?Python
You can use the __file__ attribute of a module to retrieve its path.
- PHP how to go one level up on dirname(__FILE__)PHP
You can use dirname(dirname(__FILE__)) to go one level up in the directory structure when using __FILE__ (which returns the current file's path).
- PHP: Read Specific Line From FilePHP
In PHP, you can read a specific line from a file using the file() function, which reads the entire file into an array, with each line of the file as an element in the array.