Java tutorial
//package com.java2s; /* * Copyright (C) 2010-12 Ciaran Gultnieks, ciaran@ciarang.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import java.io.File; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStream; public class Main { public static boolean symlink(File inFile, File outFile) { int exitCode = -1; try { Process sh = Runtime.getRuntime().exec("sh"); OutputStream out = sh.getOutputStream(); String command = "/system/bin/ln -s " + inFile + " " + outFile + "\nexit\n"; out.write(command.getBytes("ASCII")); final char buf[] = new char[40]; InputStreamReader reader = new InputStreamReader(sh.getInputStream()); while (reader.read(buf) != -1) throw new IOException("stdout: " + new String(buf)); reader = new InputStreamReader(sh.getErrorStream()); while (reader.read(buf) != -1) throw new IOException("stderr: " + new String(buf)); exitCode = sh.waitFor(); } catch (IOException e) { e.printStackTrace(); return false; } catch (InterruptedException e) { e.printStackTrace(); return false; } return exitCode == 0; } }