-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.java
More file actions
30 lines (26 loc) · 766 Bytes
/
Test.java
File metadata and controls
30 lines (26 loc) · 766 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Java Program to Convert File to a Byte Array
// Using Files.readAllBytes() Method
// Importing required classes
import java.io.*;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
// Main class
public class Test {
// Main driver method
public static void main(String[] args)
throws IOException,FileNotFoundException
{
// Creating an object of Path class and
// assigning local directory path of file to it
Path path = Paths.get(
"/IOStream/read.txt");
// Converting the file into a byte array
// using Files.readAllBytes() method
byte[] arr = Files.readAllBytes(path);
// Printing the above byte array
System.out.println(Arrays.toString(arr));
}
}