Skip to content

Commit 3a101bd

Browse files
author
DENIS APOLINARIO DA SILVA
committed
testes
1 parent bf359fe commit 3a101bd

File tree

4 files changed

+123
-0
lines changed

4 files changed

+123
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
2+
3+
import java.io.File;
4+
import java.io.IOException;
5+
import java.nio.file.Files;
6+
import java.nio.file.Paths;
7+
8+
public class SubstituirValorTagXml {
9+
10+
private static final String PATH = "C:\\work\\propostas\\propostas_2017_01\\";
11+
private static final String PATH_SAIDA = "C:\\work\\propostas\\propostas_2017_01_saida\\";
12+
13+
//private static final String PATH = "C:\\ambienteDesenv\\propostas_2017_01\\";
14+
//private static final String PATH_SAIDA = "C:\\ambienteDesenv\\propostas_2017_01_saida\\";
15+
16+
public static void main(String[] args) {
17+
try {
18+
File arquivos[];
19+
File diretorio = new File(PATH);
20+
arquivos = diretorio.listFiles();
21+
22+
for (int i = 0; i < arquivos.length; i++) {
23+
24+
File nomeArquivo = arquivos[i];
25+
System.out.println(nomeArquivo);
26+
String content = new String(Files.readAllBytes(Paths.get(nomeArquivo.getCanonicalPath())));
27+
28+
int indexOf = content.indexOf("<cd_cttppo>");
29+
int indexfim = content.indexOf("</cd_cttppo>");
30+
31+
String stringQueSeraSubstituida = content.substring(indexOf, indexfim);
32+
33+
int indexofFim = stringQueSeraSubstituida.indexOf(">");
34+
int cd_cttppo = Integer.parseInt(stringQueSeraSubstituida.substring(indexofFim + 1));
35+
36+
cd_cttppo = cd_cttppo + 1;
37+
38+
System.out.println(stringQueSeraSubstituida);
39+
String novoValor = "<cd_cttppo>" + cd_cttppo;
40+
content = content.replace(stringQueSeraSubstituida, novoValor);
41+
// VERIFICAR SE O ARQUIVO JA EXISTE
42+
Files.write(Paths.get(PATH_SAIDA + nomeArquivo.getName()), content.getBytes());
43+
}
44+
45+
} catch (IOException e) {
46+
e.printStackTrace();
47+
}
48+
}
49+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package org.java8;
2+
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStream;
6+
import java.io.InputStreamReader;
7+
import java.util.stream.Collectors;
8+
9+
public class ExemploInputStream {
10+
public static void main(String[] args) {
11+
}
12+
13+
private static String read(InputStream input) throws IOException {
14+
try (BufferedReader buffer = new BufferedReader(new InputStreamReader(input))) {
15+
return buffer.lines().collect(Collectors.joining("\n"));
16+
}
17+
}
18+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package org.java8;
2+
3+
import java.io.File;
4+
import java.io.FileInputStream;
5+
import java.io.FileOutputStream;
6+
import java.io.InputStream;
7+
import java.io.OutputStream;
8+
import java.nio.file.StandardCopyOption;
9+
10+
public class FilesCopy {
11+
public static void main(String[] args) {
12+
try {
13+
// Exemplo 1
14+
InputStream initialStream = new FileInputStream(new File("src/main/resources/sample.txt"));
15+
File targetFile = new File("src/main/resources/targetFile.tmp");
16+
17+
java.nio.file.Files.copy(initialStream, targetFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
18+
19+
// Exemplo 2
20+
InputStream initialStream1 = new FileInputStream(new File("src/main/resources/sample.txt"));
21+
byte[] buffer = new byte[initialStream1.available()];
22+
initialStream.read(buffer);
23+
24+
File targetFile1 = new File("src/main/resources/targetFile.tmp");
25+
OutputStream outStream = new FileOutputStream(targetFile1);
26+
outStream.write(buffer);
27+
28+
} catch (Exception e) {
29+
// TODO Auto-generated catch block
30+
e.printStackTrace();
31+
}
32+
}
33+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package org.java8;
2+
3+
public class TestString {
4+
5+
public static void main(String[] args) {
6+
String s1 = "java";
7+
String s2 = "java";
8+
String s3 = new String("java");
9+
if (s1 == s2) {
10+
System.out.println("s1 == s2");
11+
}
12+
if (s1.equals(s2)) {
13+
System.out.println("s1.equals(s2)");
14+
}
15+
if (s1 == s3) {
16+
System.out.println("s1 == s3");
17+
}
18+
if (s1.equals(s3)) {
19+
System.out.println("s1.equals(3)");
20+
}
21+
22+
}
23+
}

0 commit comments

Comments
 (0)