Here you can find the source of saveMidiFile(File file)
public static void saveMidiFile(File file)
//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(); } } }