Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- public class t5 {
- public static void main(String[] args) {
- String os = System.getProperty("os.name");
- Runtime run = Runtime.getRuntime();
- String comando;
- if (os.matches("Linux")) {
- try {
- comando = "touch " + System.getProperty("user.home") + "/Documentos/cadastrosAlms.txt";
- run.exec(comando);
- System.out.println("Arquivo \"cadastrosAlms.txt\" criado em " + System.getProperty("user.home") + "/Documentos");
- } catch (IOException ex) {
- System.out.println("Não foi possível criar o arquivo");
- System.out.println("\terro: " + ex);
- }
- finally {
- System.out.println("Encerrando a execução");
- }
- } else if (os.matches("Windows(.*)")) {
- try {
- comando = "copy NUL " + System.getProperty("user.home") + "\\Documents\\cadastrosAlms.txt";
- run.exec(comando);
- System.out.println("Arquivo \"cadastrosAlms.txt\" criado em " + System.getProperty("user.home") + "\\Documentos");
- } catch (IOException ex) {
- System.out.println("Não foi possível criar o arquivo");
- System.out.println("\terro: " + ex);
- }
- finally {
- System.out.println("Encerrando a execução");
- }
- } else {
- System.out.println("Sistema operacional não suportado pelo programa");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement