Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3d9db11

Browse files
committed
FIleSystem. Path & Directories
1 parent 731ac3a commit 3d9db11

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1246
-0
lines changed

‎Input & Output/008_FileSystem/.idea/misc.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Input & Output/008_FileSystem/.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Input & Output/008_FileSystem/.idea/workspace.xml

Lines changed: 87 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
</component>
11+
</module>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
File in some random location on the file system.
2+
Quisque at pellentesque neque.
3+
Etiam mollis dolor et congue congue.
4+
Curabitur eleifend lacinia sapien, et dictum nibh.
5+
Integer id finibus ex, at gravida leo.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
File within the working directory.
2+
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
3+
Ut suscipit eu lectus non volutpat.
4+
In consequat ac lacus vitae ornare.
5+
Vestibulum cursus urna tellus, vitae placerat elit euismod in.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
File within subdirectory.
2+
In consequat ac lacus vitae ornare.
3+
Vestibulum cursus urna tellus, vitae placerat elit euismod in.
4+
Aliquam at lobortis lacus.
2.03 KB
Binary file not shown.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import java.io.BufferedReader;
2+
import java.io.IOException;
3+
import java.nio.file.FileSystems;
4+
import java.nio.file.Files;
5+
import java.nio.file.Path;
6+
import java.nio.file.Paths;
7+
8+
public class Main {
9+
10+
public static void main(String[] args) {
11+
Path path = FileSystems.getDefault().getPath("WorkingDirectoryFile.txt");
12+
printFile(path);
13+
// Path filePath = FileSystems.getDefault().getPath("files", "SubdirectoryFile.txt");
14+
Path filePath = Paths.get(".", "files", "SubdirectoryFile.txt");
15+
printFile(filePath);
16+
filePath = Paths.get("/JAVA MasterClass/Input & Output", "/008_FileSystem", "OutThere.txt");
17+
// filePath = Paths.get("D:\\", "Examples", OutThere.txt");
18+
// D:\\Examples\\OutThere.txt
19+
printFile(filePath);
20+
21+
filePath = Paths.get(".");
22+
System.out.println(filePath.toAbsolutePath());
23+
// D:\Examples\.\subfolder\..\directory
24+
// D:\Examples\directory
25+
Path path2 = FileSystems.getDefault().getPath(".", "files", "..", "files", "SubdirectoryFile.txt");
26+
System.out.println(path2.normalize().toAbsolutePath());
27+
printFile(path2.normalize());
28+
29+
30+
}
31+
32+
private static void printFile(Path path) {
33+
try(BufferedReader fileReader = Files.newBufferedReader(path)) {
34+
String line;
35+
while((line = fileReader.readLine()) != null) {
36+
System.out.println(line);
37+
}
38+
} catch(IOException e) {
39+
System.out.println(e.getMessage());
40+
e.printStackTrace();
41+
}
42+
}
43+
}

‎Input & Output/009_Path/.idea/misc.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /