Example usage for java.io File File

List of usage examples for java.io File File

Introduction

In this page you can find the example usage for java.io File File.

Prototype

public File(URI uri) 

Source Link

Document

Creates a new File instance by converting the given file: URI into an abstract pathname.

Usage

From source file:Main.java

public static void main(String[] args) {

    // create a new list of arguments for our process
    String[] list = { "notepad.exe", "test.txt" };

    // create the process builder
    ProcessBuilder pb = new ProcessBuilder(list);
    try {/*from   w w w. j a  v a  2  s  .  c o m*/

        pb = pb.redirectOutput(new File("c:/"));
        pb.start();
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    File file = new File("data.xml");
    DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    Document doc = builder.parse(file);

    NodeList nodes = doc.getElementsByTagName("topic");
    for (int i = 0; i < nodes.getLength(); i++) {
        Element element = (Element) nodes.item(i);
        NodeList title = element.getElementsByTagName("title");
        Element line = (Element) title.item(0);
        System.out.println("Title: " + getCharacterDataFromElement(line));
    }/*ww  w . ja v a2  s  .co  m*/
}

From source file:com.ltb.Main.java

public static void main(String[] args) throws Exception {
    File node = new File("//home//juanma//Videos//DSVideo//Cartoons");

    displayIt(node);/*from w  ww.j a  v  a2s .  c o m*/

    AudioTrack.returnListLanguages();

    System.out.println("# Audio tracks " + audio);

    System.exit(0);
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    createFile();//from ww w .ja  v  a2  s.c om

    File aFile = new File("C:/primes.bin");
    FileInputStream inFile = new FileInputStream(aFile);

    FileChannel inChannel = inFile.getChannel();

    final int PRIMESREQUIRED = 10;
    ByteBuffer buf = ByteBuffer.allocate(8 * PRIMESREQUIRED);

    long[] primes = new long[PRIMESREQUIRED];
    int index = 0; // Position for a prime in the file

    // Count of primes in the file
    final int PRIMECOUNT = (int) inChannel.size() / 8;

    // Read the number of random primes required
    for (int i = 0; i < PRIMESREQUIRED; i++) {
        index = 8 * (int) (PRIMECOUNT * Math.random());
        inChannel.read(buf, index); // Read the value
        buf.flip();
        primes[i] = buf.getLong(); // Save it in the array
        buf.clear();
    }

    for (long prime : primes) {
        System.out.printf("%12d", prime);
    }
    inFile.close(); // Close the file and the channel

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    File file = new File("yourXML.xml");
    FileInputStream inputStream = new FileInputStream(file);
    XMLInputFactory inputFactory = XMLInputFactory.newInstance();
    XMLStreamReader reader = inputFactory.createXMLStreamReader(inputStream);

    System.out.println(reader.getVersion());
    System.out.println(reader.isStandalone());
    System.out.println(reader.standaloneSet());
    System.out.println(reader.getEncoding());
    System.out.println(reader.getCharacterEncodingScheme());

    parseRestOfDocument(reader);//w  ww .java  2  s. c o  m
}

From source file:MainClass.java

public static void main(String[] args) {

    String phrase = new String("www.java2s.com API \n");
    File aFile = new File("test.txt");

    FileOutputStream file = null;
    try {//w  ww  .  j a  v  a2s . com
        file = new FileOutputStream(aFile, true);
    } catch (FileNotFoundException e) {
        e.printStackTrace(System.err);
    }
    FileChannel outChannel = file.getChannel();
    ByteBuffer buf = ByteBuffer.allocate(phrase.length());
    byte[] bytes = phrase.getBytes();
    buf.put(bytes);
    buf.flip();

    try {
        outChannel.write(buf);
        file.close();
    } catch (IOException e) {
        e.printStackTrace(System.err);
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    FileInputStream in1 = new FileInputStream(new File("file1.xml"));
    FileInputStream in2 = new FileInputStream(new File("file2.xml"));

    System.out.println(digest(in1));
    System.out.println(digest(in2));
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    AudioInputStream stream = AudioSystem.getAudioInputStream(new File("audiofile"));

    // From URL/*from   w ww .  ja  va  2s.  c o m*/
    // stream = AudioSystem.getAudioInputStream(new URL(
    // "http://hostname/audiofile"));

    AudioFormat format = stream.getFormat();
    if (format.getEncoding() != AudioFormat.Encoding.PCM_SIGNED) {
        format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, format.getSampleRate(),
                format.getSampleSizeInBits() * 2, format.getChannels(), format.getFrameSize() * 2,
                format.getFrameRate(), true); // big endian
        stream = AudioSystem.getAudioInputStream(format, stream);
    }

    DataLine.Info info = new DataLine.Info(Clip.class, stream.getFormat(),
            ((int) stream.getFrameLength() * format.getFrameSize()));
    Clip clip = (Clip) AudioSystem.getLine(info);

    clip.open(stream);

    clip.start();
}

From source file:Main.java

public static void main(String[] a) {
    JFrame frame = new JFrame("JFileChooser Popup");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JFileChooser fileChooser = new JFileChooser(".");
    fileChooser.ensureFileIsVisible(new File("."));

    frame.add(fileChooser, BorderLayout.CENTER);

    frame.pack();// ww w . j a  v  a 2s  .  c om
    frame.setVisible(true);
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    ProcessBuilder launcher = new ProcessBuilder();
    Map<String, String> environment = launcher.environment();
    launcher.redirectErrorStream(true);/*from   w  ww  .j  a v a  2 s. co m*/
    launcher.directory(new File("c:\\"));

    environment.put("name", "var");
    launcher.command("notepad.exe");
    Process p = launcher.start(); // And launch a new process
    BufferedReader output = new BufferedReader(new InputStreamReader(p.getInputStream()));
    String line;
    while ((line = output.readLine()) != null)
        System.out.println(line);

    // The process should be done now, but wait to be sure.
    p.waitFor();

}