Java Midi File Save saveMidiFile(File file)

Here you can find the source of saveMidiFile(File file)

Description

save Midi File

License

Open Source License

Declaration

public static void saveMidiFile(File file) 

Method Source Code


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

import java.io.File;
import java.io.IOException;
import javax.sound.midi.*;

public class Main {
    static Sequence sequence;

    public static void saveMidiFile(File file) {
        try {// w w w  .  ja v  a  2s. co m
            int[] fileTypes = MidiSystem.getMidiFileTypes(sequence);
            if (fileTypes.length == 0) {
                System.out.println("Can't save sequence");
            } else {
                if (MidiSystem.write(sequence, fileTypes[0], file) == -1) {
                    throw new IOException("Problems writing to file");
                }
            }
        } catch (SecurityException ex) {
            ex.printStackTrace();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}

Related

  1. saveMidiFile(Sequence sequence, String filename)