build Shell Exe Batch Files - Android Android OS

Android examples for Android OS:Shell

Description

build Shell Exe Batch Files

Demo Code


//package com.book2s;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

public class Main {
    private static final String batchDir = System.getProperty("user.dir")
            + "\\batch\\";

    private static void buildExeBatchFiles(String command, String fileName) {
        System.out.println(command);
        if (!new File(batchDir).exists()) {
            new File(batchDir).mkdirs();
        }/*from  w ww.j a v  a 2  s .com*/
        String filePath = batchDir + fileName;
        try {
            writeFile(filePath, command);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static void writeFile(String filePath, String content)
            throws IOException {
        FileWriter fw = new FileWriter(filePath);
        PrintWriter out = new PrintWriter(fw);
        out.write(content);
        out.println();
        fw.close();
        out.close();
    }
}

Related Tutorials