Java Midi File Save saveMidiFile(Sequence sequence, String filename)

Here you can find the source of saveMidiFile(Sequence sequence, String filename)

Description

Saves a Sequence to a file.

License

Open Source License

Parameter

Parameter Description
sequence The <code>Sequence</code> to save.
filename The path to the file to save to. Relative paths are relative to the program's running directory.

Exception

Parameter Description
IOException If there was a problem saving the file.

Declaration

public static void saveMidiFile(Sequence sequence, String filename) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.File;
import java.io.IOException;

import javax.sound.midi.MidiSystem;

import javax.sound.midi.Sequence;

public class Main {
    /**//w  ww  .  ja  v  a 2s  .  c o  m
     * Saves a <code>Sequence</code> to a file.
     * 
     * @param sequence The <code>Sequence</code> to save.
     * @param filename The path to the file to save to. Relative paths are
     *      relative to the program's running directory.
     * @throws IOException If there was a problem saving the file.
     */
    public static void saveMidiFile(Sequence sequence, String filename) throws IOException {
        int[] fileTypes = MidiSystem.getMidiFileTypes(sequence);
        File file = new File(filename);
        MidiSystem.write(sequence, fileTypes[0], file);
    }
}

Related

  1. saveMidiFile(File file)