-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Métodos readString() e writeString() da classe Files
- Loading branch information
1 parent
9f55222
commit a977468
Showing
8 changed files
with
156 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
Secao-5-Java-11-New-Features/aula-32/MeuProjetoLambda/MeuProjetoLambda.iml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module type="JAVA_MODULE" version="4"> | ||
<component name="NewModuleRootManager" inherit-compiler-output="true"> | ||
<exclude-output /> | ||
<content url="file://$MODULE_DIR$"> | ||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> | ||
</content> | ||
<orderEntry type="inheritedJdk" /> | ||
<orderEntry type="sourceFolder" forTests="false" /> | ||
</component> | ||
</module> |
12 changes: 12 additions & 0 deletions
12
Secao-5-Java-11-New-Features/aula-32/MeuProjetoLambda/src/MinhaClasseLambda.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import java.util.function.Function; | ||
|
||
public class MinhaClasseLambda { | ||
public static void main(String[] args) { | ||
|
||
String str = "Java Tópicos Avançados"; | ||
|
||
Function<String, String> concatena = (var s) -> s + ". "; | ||
|
||
|
||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Secao-5-Java-11-New-Features/aula-33/MeuProjetoFiles/MeuProjetoFiles.iml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module type="JAVA_MODULE" version="4"> | ||
<component name="NewModuleRootManager" inherit-compiler-output="true"> | ||
<exclude-output /> | ||
<content url="file://$MODULE_DIR$"> | ||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> | ||
</content> | ||
<orderEntry type="inheritedJdk" /> | ||
<orderEntry type="sourceFolder" forTests="false" /> | ||
</component> | ||
</module> |
1 change: 1 addition & 0 deletions
1
Secao-5-Java-11-New-Features/aula-33/MeuProjetoFiles/meutexto.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Curso Java T�picos Avan�ados |
53 changes: 53 additions & 0 deletions
53
Secao-5-Java-11-New-Features/aula-33/MeuProjetoFiles/src/EscreveArquivo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import java.io.BufferedWriter; | ||
import java.io.File; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
|
||
public class EscreveArquivo { | ||
|
||
public static void main(String[] args) { | ||
// TODO Auto-generated method stub | ||
|
||
String caminho = "/mnt/Conteúdos Estudantil (mnt)/Udemy Courses/Marco Aurélio Regis/java-topicos-avancados/Secao-5-Java-11-New-Features/aula-33/MeuProjetoFiles/meutexto.txt"; | ||
String meutexto = "Curso Java Tópicos Avançados"; | ||
|
||
/*********************************************************************************/ | ||
|
||
/* | ||
* Escreve fluxos de caracteres (string) em arquivo. | ||
* Maneira mais simples até então. | ||
* Indicado para poucas operações de escrita. | ||
*/ | ||
|
||
try(FileWriter myWriter = new FileWriter(caminho)) { | ||
myWriter.write(meutexto); | ||
} | ||
catch (IOException e) { | ||
} | ||
|
||
/*********************************************************************************/ | ||
|
||
/* | ||
* Grava o texto em uma stream de saída, usando mecanismo de buffer | ||
* para gravação mais eficiente de caracteres. | ||
*/ | ||
|
||
try(BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(caminho))) { | ||
bufferedWriter.write(meutexto); | ||
} | ||
catch (IOException e) { | ||
} | ||
|
||
/*********************************************************************************/ | ||
|
||
try { | ||
Files.writeString(new File(caminho).toPath(), meutexto, StandardCharsets.ISO_8859_1); | ||
} | ||
catch (IOException e) { | ||
} | ||
|
||
} | ||
|
||
} |
65 changes: 65 additions & 0 deletions
65
Secao-5-Java-11-New-Features/aula-33/MeuProjetoFiles/src/LeArquivo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import java.io.BufferedReader; | ||
import java.io.File; | ||
import java.io.FileReader; | ||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
|
||
public class LeArquivo { | ||
|
||
public static void main(String[] args) { | ||
// TODO Auto-generated method stub | ||
|
||
String caminho = "meutexto.txt"; | ||
|
||
/*********************************************************************************/ | ||
|
||
/* | ||
* Leitura fluxos de caracteres (string). | ||
* Maneira mais simples até então. | ||
* Indicado para poucas operações de leitura. | ||
*/ | ||
|
||
try(FileReader myReader = new FileReader(caminho)) { | ||
int i; | ||
|
||
while((i=myReader.read())!=-1) //-1 = EOF | ||
System.out.print((char)i); | ||
|
||
System.out.println(); | ||
} | ||
catch (IOException e) { | ||
} | ||
|
||
/*********************************************************************************/ | ||
|
||
/* | ||
* Lê o texto em uma stream de entrada, usando mecanismo de buffer | ||
* para leitura mais eficiente de caracteres. | ||
*/ | ||
|
||
try(BufferedReader bufferedReader = new BufferedReader(new FileReader(caminho))) { | ||
String s; | ||
|
||
while ((s = bufferedReader.readLine()) != null) { //null = EOF | ||
System.out.println(s); | ||
} | ||
} | ||
catch (IOException e) { | ||
} | ||
|
||
/*********************************************************************************/ | ||
|
||
String s; | ||
try { | ||
s = Files.readString(new File(caminho).toPath(), StandardCharsets.ISO_8859_1); | ||
System.out.println(s); | ||
} | ||
catch (IOException e) { | ||
System.out.println(e); | ||
} | ||
|
||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Curso Java T�picos Avan�ados |