Advertisement
LightProgrammer000

Arvore do sistema + Diretorio

May 7th, 2020
1,238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.04 KB | None | 0 0
  1. package C_Xti_010_Files;
  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 Arquivo1
  9. {
  10.     public static void main(String[] args) throws IOException
  11.     {
  12.         // Java 7
  13.         //Path path = Paths.get("c:/xti/files/virus.bat");
  14.         Path path = Paths.get("c:/file/virus.bat");
  15.         System.out.println(path.toAbsolutePath());
  16.         System.out.println(path.getParent());
  17.         System.out.println(path.getRoot());
  18.         System.out.println(path.getFileName());
  19.  
  20.         // Criação de diretórios
  21.         Files.createDirectories(path.getParent());
  22.  
  23.         // Escrever e ler arquivos
  24.         byte[] bytes = ("@echo off \n" +
  25.                         "mkdir %userprofile%\\desktop\\oi \n" +
  26.                         "cd / \n" +
  27.                         "tree ").getBytes();
  28.        
  29.         Files.write(path, bytes); //cria,limpa,escreve
  30.  
  31.         byte[] retorno = Files.readAllBytes(path);
  32.         System.out.println(new String(retorno));
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement