add files
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
package org.FileExamples.AddresesingModes;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class FileAddressing {
|
||||
static void main() {
|
||||
//relative
|
||||
Path relativePath = Path.of("data.txt");
|
||||
//absolute
|
||||
Path absolutePath = Path.of("C:\\Users\\Lenovo\\data.txt");
|
||||
|
||||
|
||||
//using class path / resources
|
||||
InputStream input = FileAddressing.class
|
||||
.getClassLoader()
|
||||
.getResourceAsStream("data.txt");
|
||||
|
||||
Scanner scanner = new Scanner(input);
|
||||
|
||||
while (scanner.hasNextLine()) {
|
||||
System.out.println(scanner.nextLine());
|
||||
}
|
||||
|
||||
scanner.close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user