Java File IO
- 14 February
Count Files in Directory in Java
Using java.io.File Class Before moving forwards, it is important to know the available items in the current directory. You may also create the same structure to follow along with this article. Our current directory (E:\Test) has the following structure: E:\Test – It has seven items, four text files and three folders (FolderA, FolderB, FolderC, File1.txt, […]
- 16 September
How to Remove Extension from Filename in Java
In this post, we will see how to remove extension from filename in java. Ways to Remove extension from filename in java There are multiple ways to remove extension from filename in java. Let’s go through them. Using substring() and lastIndexOf() methods You can first find last index of dot(.) using String’s lastIndexOf() method and […]
- 15 September
How to Get Temp Directory Path in Java
In this post, we will see how to get temp directory path in java. Get Temp Directory Path in Java Using System.getProperty() To get the temp directory path, you can simply use System.getProperty("java.io.tmpdir"). It will return default temporary folder based on your operating system. Default temp directory path Windows : %USER%\AppData\Local\Temp Linux/Unix: /tmp Let’s see […]
- 16 February
Convert Outputstream to Byte Array in Java
In this post, we will see how to convert OutputStream to Byte array in Java. Convert OutputStream to Byte array in Java Here are steps to convert OutputStream to Byte array in java. Create instance of ByteArrayOutputStream baos Write data to ByteArrayOutputStream baos Extract byte[] using toByteArray() method. [crayon-6767bbb534279749473846/] Output: Print output: Java2blog Convert OutputStream […]
- 27 December
How to get current working directory in java
Learn about how to get current working directory in java using different ways
- 08 August
Difference between Scanner and BufferReader in java
In this post, we will see difference between Scanner and BufferReader in java. Java has two classes that have been used for reading files for a very long time. These two classes are Scanner and BufferedReader. In this post, we are going to find major differences and similarities between the two classes. Introduction Let’s first […]
- 29 March
Read UTF-8 Encoded Data in java
In this post, we will see how to read UTF-8 Encoded Data. Sometimes, we have to deal with UTF-8 Encoded Data in our application. It may be due localization or may be processing data from user input. There are multiple ways to read UTF-8 Encoded Data in Java. Using Files’s newBufferedReader() We can use java.nio.file.Files's […]
- 29 March
Write UTF-8 Encoded Data in java
In this post, we will see how to write UTF-8 Encoded Data. Sometimes, we have to deal with UTF-8 Encoded Data in our application. It may be due localization or may be processing data from user input. We will use Hindi language sentences to write in file. There are three ways to write UTF-8 Encoded […]
- 15 March
Java read file line by line
In this post, we will see different ways to read file line by line in java. Sometimes, we need to read file line by line to a String, and process it. Here are different ways to read file line by line in java. Java 8 Streams Java 8 has introduced a new method called lines() […]