NIO2 API returns its own DirectoryStream object, which implements the Iterable interface. ![]() Moreover, the NIO2 API has the toRealPath() and normalize() methods that we can use to remove redundancies.Ĭonversion to URI can be done by using the toUri() methods: URI fileUri = file.toURI() Īlso, we can list the directory content: // java.io APIĭirectoryStream paths = Files.newDirectoryStream(path) While the Path object is immutable, it returns a new instance. Path canonicalPath = path.toRealPath().normalize() Path absolutePath = path.toAbsolutePath() But, for reading streams of characters, it is recommended to use FileReader class. It is used for reading byte-oriented data (streams of raw bytes) such as image data, audio, video etc. This class inherits from the InputStreamReader class. Java FileInputStream class obtains input bytes from a file. It is a character-oriented class that is used for file handling in java. It returns data in byte format like FileInputStream class. So starting of with FileReader class in java is used to read data from the file. String canonicalPathStr = file.getCanonicalPath() Here first we will be discussing out FileReader class. String absolutePathStr = file.getAbsolutePath() To get absolute or canonical paths, we can use: // java.io API ![]() ![]() Be aware that, unlike the previous examples, most of them are performed directly on object instances. In the end, let's quickly look at methods in the File class for getting the filesystem path.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |