Advertisement
LightProgrammer000

Criando diretorios

May 7th, 2020
1,226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.85 KB | None | 0 0
  1. package PXTI_002;
  2.  
  3. import java.io.IOException;
  4. import java.nio.file.Files;
  5. import java.nio.file.Path;
  6. import java.nio.file.Paths;
  7.  
  8. public class Arquivo
  9. {
  10.     public static void main(String[] args) throws IOException
  11.     {
  12.         //Java 7
  13.         Path path = Paths.get("c:/xti/files/test_virus.bat");
  14.         System.out.println(path.toAbsolutePath());
  15.         System.out.println(path.getParent());
  16.         System.out.println(path.getRoot());
  17.         System.out.println(path.getFileName());
  18.  
  19.         // Criação de diretórios
  20.         Files.createDirectories(path.getParent());
  21.  
  22.         // Escrever e ler arquivos
  23.         byte[] bytes = "echo codigo_virus > virus.txt".getBytes();
  24.         Files.write(path, bytes); //cria,limpa,escreve
  25.  
  26.         byte[] retorno = Files.readAllBytes(path);
  27.         System.out.println(new String(retorno));
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement