Skip to content

Commit fea3267

Browse files
committed
feat(file-io): 🎸 files, translated
Refers: #9
1 parent 3ef7e75 commit fea3267

17 files changed

+251
-264
lines changed

book/07-file-io/sections/02-files.asc

Lines changed: 121 additions & 122 deletions
Large diffs are not rendered by default.

src/org/j6toj8/fileio/files/Files_BasicFileAttributeView.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,23 @@ public static void main(String[] args) {
1616
String userHome = System.getProperty("user.home");
1717
System.out.println("User home: " + userHome);
1818

19-
Path path = Paths.get(userHome, "arquivo.txt");
19+
Path path = Paths.get(userHome, "file.txt");
2020

2121
try {
2222
BasicFileAttributeView attributesView = Files.getFileAttributeView(path, BasicFileAttributeView.class);
23-
BasicFileAttributes attributesAntigos = attributesView.readAttributes();
23+
BasicFileAttributes oldAttributes = attributesView.readAttributes();
2424

25-
System.out.println("\nData de Criação original: " + attributesAntigos.creationTime());
26-
System.out.println("Último acesso original: " + attributesAntigos.lastAccessTime());
27-
System.out.println("Última modificação original: " + attributesAntigos.lastModifiedTime());
25+
System.out.println("\nOriginal creation date: " + oldAttributes.creationTime());
26+
System.out.println("Original last access: " + oldAttributes.lastAccessTime());
27+
System.out.println("Original last modified: " + oldAttributes.lastModifiedTime());
2828

2929
FileTime fileTime = FileTime.from(Instant.now().plusMillis(10000));
3030
attributesView.setTimes(fileTime, fileTime, fileTime);
3131

32-
BasicFileAttributes attributesNovos = attributesView.readAttributes();
33-
System.out.println("\nData de Criação alterada: " + attributesNovos.creationTime());
34-
System.out.println("Último acesso alterada: " + attributesNovos.lastAccessTime());
35-
System.out.println("Última modificação alterada: " + attributesNovos.lastModifiedTime());
32+
BasicFileAttributes newAttributes = attributesView.readAttributes();
33+
System.out.println("\nCreation date changed: " + newAttributes.creationTime());
34+
System.out.println("Last access changed: " + newAttributes.lastAccessTime());
35+
System.out.println("Last modified changed: " + newAttributes.lastModifiedTime());
3636
} catch (IOException e) {
3737
e.printStackTrace();
3838
}

src/org/j6toj8/fileio/files/Files_BasicFileAttributes.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@ public static void main(String[] args) {
1313
String userHome = System.getProperty("user.home");
1414
System.out.println("User home: " + userHome);
1515

16-
Path path = Paths.get(userHome, "arquivo.txt");
16+
Path path = Paths.get(userHome, "file.txt");
1717

1818
try {
1919
BasicFileAttributes attributes = Files.readAttributes(path, BasicFileAttributes.class);
20-
System.out.println("Tamanho: " + attributes.size());
20+
System.out.println("Size: " + attributes.size());
2121

22-
System.out.println("É diretório? " + attributes.isDirectory());
23-
System.out.println("É link simbólico? " + attributes.isSymbolicLink());
24-
System.out.println("É um arquivo comum? " + attributes.isRegularFile());
25-
System.out.println("Não é nenhuma das opções acima? " + attributes.isOther());
22+
System.out.println("Is it directory? " + attributes.isDirectory());
23+
System.out.println("Is it symbolic link? " + attributes.isSymbolicLink());
24+
System.out.println("Is it a common file? " + attributes.isRegularFile());
25+
System.out.println("Not any of the above? " + attributes.isOther());
2626

27-
System.out.println("Data de Criação: " + attributes.creationTime());
28-
System.out.println("Último acesso: " + attributes.lastAccessTime());
29-
System.out.println("Última modificação: " + attributes.lastModifiedTime());
27+
System.out.println("Creation date: " + attributes.creationTime());
28+
System.out.println("Last acess: " + attributes.lastAccessTime());
29+
System.out.println("Last Modified: " + attributes.lastModifiedTime());
3030
} catch (IOException e) {
3131
e.printStackTrace();
3232
}

src/org/j6toj8/fileio/files/Files_Checks.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,44 +12,44 @@ public static void main(String[] args) {
1212
String userHome = System.getProperty("user.home");
1313
System.out.println("User home: " + userHome);
1414

15-
Path path1 = Paths.get(userHome, "arquivo1.txt");
16-
Path path2 = Paths.get(userHome, "arquivos");
15+
Path path1 = Paths.get(userHome, "file1.txt");
16+
Path path2 = Paths.get(userHome, "files");
1717

1818
System.out.println("Path 1: " + path1);
1919
System.out.println("Path 2: " + path2);
2020

21-
System.out.println("Path 1 existe? " + Files.exists(path1));
22-
System.out.println("Path 2 existe? " + Files.exists(path2));
21+
System.out.println("Path 1 exist? " + Files.exists(path1));
22+
System.out.println("Path 2 exist? " + Files.exists(path2));
2323

24-
System.out.println("Path 1 NÃO existe? " + Files.notExists(path1));
25-
System.out.println("Path 2 NÃO existe? " + Files.notExists(path2));
24+
System.out.println("Path 1 does NOT exist? " + Files.notExists(path1));
25+
System.out.println("Path 2 does NOT exist? " + Files.notExists(path2));
2626

27-
System.out.println("Path 1 é um diretório? " + Files.isDirectory(path1));
28-
System.out.println("Path 1 é um arquivo comum? " + Files.isRegularFile(path1));
29-
System.out.println("Path 1 é um link simbólico? " + Files.isSymbolicLink(path1));
27+
System.out.println("Is Path 1 a directory? " + Files.isDirectory(path1));
28+
System.out.println("Is Path 1 a common file? " + Files.isRegularFile(path1));
29+
System.out.println("Is Path 1 a symbolic link? " + Files.isSymbolicLink(path1));
3030

31-
System.out.println("Aplicação possui permissão de leitura no Path 1? " + Files.isReadable(path1));
32-
System.out.println("Aplicação possui permissão de escrita no Path 1? " + Files.isWritable(path1));
33-
System.out.println("Aplicação possui permissão de execução no Path 1? " + Files.isExecutable(path1));
31+
System.out.println("Application has read permission on Path 1? " + Files.isReadable(path1));
32+
System.out.println("Application has write permission on Path 1? " + Files.isWritable(path1));
33+
System.out.println("Application has execution permission on Path 1? " + Files.isExecutable(path1));
3434

3535
try {
36-
System.out.println("Qual o tamanho de Path 1? " + Files.size(path1));
36+
System.out.println("How big is Path 1? " + Files.size(path1));
3737
} catch (IOException e1) {
38-
// Lança exceção se o arquivo não existir
38+
// Throw exception if file does not exist
3939
e1.printStackTrace();
4040
}
4141

4242
try {
43-
System.out.println("Path 1 é oculto? " + Files.isHidden(path1));
43+
System.out.println("Is Path 1 hidden? " + Files.isHidden(path1));
4444
} catch (IOException e) {
45-
// Lança exceção se o arquivo não existir
45+
// Throw exception if file does not exist
4646
e.printStackTrace();
4747
}
4848

4949
try {
50-
System.out.println("Path 1 e Path 1 são iguais? " + Files.isSameFile(path1, path1));
50+
System.out.println("Are Path 1 and Path 1 the same? " + Files.isSameFile(path1, path1));
5151
} catch (IOException e) {
52-
// Lança exceção se o arquivo não existir
52+
// Throw exception if file does not exist
5353
e.printStackTrace();
5454
}
5555

src/org/j6toj8/fileio/files/Files_CopyFromPath.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,16 @@ public static void main(String[] args) {
1515
String userHome = System.getProperty("user.home");
1616
System.out.println("User home: " + userHome);
1717

18-
// Utilizando um nome aleatório de arquivo,
19-
// apenas para o exemplo executar inúmeras vezes sem problemas
20-
String nomeAleatorio = "copia" + new Random().nextInt() + ".txt";
18+
// Using a random file name, just for example to run countless times without problems
19+
String randomName = "copy" + new Random().nextInt() + ".txt";
2120

22-
try (FileOutputStream fos = new FileOutputStream(userHome + File.separator + nomeAleatorio)) {
23-
Path pathParaCopia = Paths.get(userHome, "arquivo1.txt");
24-
Files.copy(pathParaCopia, fos);
21+
try (FileOutputStream fos = new FileOutputStream(userHome + File.separator + randomName)) {
22+
Path pathToCopy = Paths.get(userHome, "file1.txt");
23+
Files.copy(pathToCopy, fos);
2524

26-
Path pathCriado = Paths.get(userHome, nomeAleatorio);
27-
System.out.println("Path criado: " + pathCriado);
28-
System.out.println("Path criado existe?: " + Files.exists(pathCriado));
25+
Path createdPath = Paths.get(userHome, randomName);
26+
System.out.println("Created Path: " + createdPath);
27+
System.out.println("Created Path exist?: " + Files.exists(createdPath));
2928
} catch (IOException e) {
3029
e.printStackTrace();
3130
}

src/org/j6toj8/fileio/files/Files_CopyPath.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,21 @@ public static void main(String[] args) {
1313
String userHome = System.getProperty("user.home");
1414
System.out.println("User home: " + userHome);
1515

16-
// Utilizando um nome aleatório de arquivo,
17-
// apenas para o exemplo executar inúmeras vezes sem problemas
18-
String nomeAleatorio = "arquivo" + new Random().nextInt() + ".txt";
16+
// Using a random file name, just for example to run countless times without problems
17+
String randomName = "file" + new Random().nextInt() + ".txt";
1918

20-
Path path1 = Paths.get(userHome, nomeAleatorio);
21-
Path path2 = Paths.get(userHome, nomeAleatorio + "-copia.txt");
19+
Path path1 = Paths.get(userHome, randomName);
20+
Path path2 = Paths.get(userHome, randomName + "-copy.txt");
2221
System.out.println("Path 1: " + path1);
2322
System.out.println("Path 2: " + path2);
2423

2524
try {
26-
System.out.println("Path 1 existe? " + Files.exists(path1));
25+
System.out.println("Path 1 exist? " + Files.exists(path1));
2726
Files.createFile(path1);
28-
System.out.println("Path 1 existe? " + Files.exists(path1));
29-
System.out.println("Path 2 existe? " + Files.exists(path2));
27+
System.out.println("Path 1 exist? " + Files.exists(path1));
28+
System.out.println("Path 2 exist? " + Files.exists(path2));
3029
Files.copy(path1, path2);
31-
System.out.println("Path 2 existe? " + Files.exists(path2));
30+
System.out.println("Path 2 exist? " + Files.exists(path2));
3231
} catch (IOException e) {
3332
e.printStackTrace();
3433
}

src/org/j6toj8/fileio/files/Files_CopyToPath.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,14 @@ public static void main(String[] args) {
1515
String userHome = System.getProperty("user.home");
1616
System.out.println("User home: " + userHome);
1717

18-
// Utilizando um nome aleatório de arquivo,
19-
// apenas para o exemplo executar inúmeras vezes sem problemas
20-
String nomeAleatorio = "copia" + new Random().nextInt() + ".txt";
18+
// Using a random file name, just for example to run countless times without problems
19+
String randomName = "copy" + new Random().nextInt() + ".txt";
2120

22-
try (FileInputStream fis = new FileInputStream(userHome + File.separator + "arquivo1.txt")) {
23-
Path pathParaCopia = Paths.get(userHome, nomeAleatorio);
24-
System.out.println("Path 2 existe? " + Files.exists(pathParaCopia));
25-
Files.copy(fis, pathParaCopia);
26-
System.out.println("Path 2 existe? " + Files.exists(pathParaCopia));
21+
try (FileInputStream fis = new FileInputStream(userHome + File.separator + "file1.txt")) {
22+
Path pathToCopy = Paths.get(userHome, randomName);
23+
System.out.println("Path 2 exist? " + Files.exists(pathToCopy));
24+
Files.copy(fis, pathToCopy);
25+
System.out.println("Path 2 exist? " + Files.exists(pathToCopy));
2726
} catch (IOException e) {
2827
e.printStackTrace();
2928
}

src/org/j6toj8/fileio/files/Files_CreateDirectories.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,24 @@ public static void main(String[] args) {
1313
String userHome = System.getProperty("user.home");
1414
System.out.println("User home: " + userHome);
1515

16-
// Utilizando um nome aleatório de diretório,
17-
// apenas para o exemplo executar inúmeras vezes sem problemas
18-
String nomeAleatorio1 = "arquivo" + new Random().nextInt();
19-
String nomeAleatorio2 = "arquivo" + new Random().nextInt();
20-
String nomeAleatorio3 = "arquivo" + new Random().nextInt();
16+
// Using a random directory name, just for example to run countless times without problems
17+
String randomName1 = "file" + new Random().nextInt();
18+
String randomName2 = "file" + new Random().nextInt();
19+
String randomName3 = "file" + new Random().nextInt();
2120

22-
Path path = Paths.get(userHome, nomeAleatorio1, nomeAleatorio2, nomeAleatorio3);
21+
Path path = Paths.get(userHome, randomName1, randomName2, randomName3);
2322
System.out.println("Path: " + path);
2423

2524
try {
26-
Files.createDirectory(path); // MÉTODO ERRADO, LANÇA EXCEÇÃO
25+
Files.createDirectory(path); // WRONG METHOD, THROWS EXCEPTION
2726
} catch (IOException e) {
2827
e.printStackTrace();
2928
}
3029

3130
try {
32-
System.out.println("Path existe? " + Files.exists(path));
31+
System.out.println("Path exist? " + Files.exists(path));
3332
Files.createDirectories(path);
34-
System.out.println("Path existe? " + Files.exists(path));
33+
System.out.println("Path exist? " + Files.exists(path));
3534
} catch (IOException e) {
3635
e.printStackTrace();
3736
}

src/org/j6toj8/fileio/files/Files_CreateDirectory.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,16 @@ public static void main(String[] args) {
1313
String userHome = System.getProperty("user.home");
1414
System.out.println("User home: " + userHome);
1515

16-
// Utilizando um nome aleatório de diretório,
17-
// apenas para o exemplo executar inúmeras vezes sem problemas
18-
String nomeAleatorio = "arquivo" + new Random().nextInt();
16+
// Using a random directory name, just for example to run countless times without problems
17+
String randomName = "file" + new Random().nextInt();
1918

20-
Path path = Paths.get(userHome, nomeAleatorio);
19+
Path path = Paths.get(userHome, randomName);
2120
System.out.println("Path: " + path);
2221

2322
try {
24-
System.out.println("Path existe? " + Files.exists(path));
23+
System.out.println("Path exist? " + Files.exists(path));
2524
Files.createDirectory(path);
26-
System.out.println("Path existe? " + Files.exists(path));
25+
System.out.println("Path exist? " + Files.exists(path));
2726
} catch (IOException e) {
2827
e.printStackTrace();
2928
}

src/org/j6toj8/fileio/files/Files_CreateFile.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,16 @@ public static void main(String[] args) {
1313
String userHome = System.getProperty("user.home");
1414
System.out.println("User home: " + userHome);
1515

16-
// Utilizando um nome aleatório de arquivo,
17-
// apenas para o exemplo executar inúmeras vezes sem problemas
18-
String nomeAleatorio = "arquivo" + new Random().nextInt() + ".txt";
16+
// Using a random file name, just for example to run countless times without problems
17+
String randomName = "file" + new Random().nextInt() + ".txt";
1918

20-
Path path = Paths.get(userHome, nomeAleatorio);
19+
Path path = Paths.get(userHome, randomName);
2120
System.out.println("Path: " + path);
2221

2322
try {
24-
System.out.println("Path existe? " + Files.exists(path));
23+
System.out.println("Path exist? " + Files.exists(path));
2524
Files.createFile(path);
26-
System.out.println("Path existe? " + Files.exists(path));
25+
System.out.println("Path exist? " + Files.exists(path));
2726
} catch (IOException e) {
2827
e.printStackTrace();
2928
}

0 commit comments

Comments
 (0)