Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 * Copyright (c)  Subhra Das Gupta
 *
 * This file is part of Xtream Download Manager.
 *
 * Xtream Download Manager 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.
 *
 * Xtream Download Manager 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 Xtream Download Manager; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

import java.awt.Desktop;
import java.io.File;
import java.io.IOException;

import java.util.ArrayList;
import java.util.List;

public class Main {
    public static void open(File f) {
        char ch = File.separatorChar;
        if (ch == '\\') {
            openWindows(f);
        } else {
            try {
                Desktop.getDesktop().open(f);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }

    private static void openWindows(File f) {
        try {
            ProcessBuilder builder = new ProcessBuilder();
            List<String> lst = new ArrayList<String>();
            lst.add("rundll32");
            lst.add("url.dll,FileProtocolHandler");
            lst.add(f.getAbsolutePath());
            builder.command(lst);
            builder.start();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}