29 lines
694 B
Java
29 lines
694 B
Java
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();
|
|
}
|
|
}
|