code: private static void exportFst(Fst fst, String filename) {
      FileWriter file;
      try {
        file = new FileWriter(filename);
        PrintWriter out = new PrintWriter(file);
  
        // print start first
        State start = fst.getStartState();
        out.println(start.getId() + "\t" + start.getFinalWeight());
  
        // print all states
        int numStates = fst.getStateCount();
        for (int i = 0; i < numStates; i++) {
          State s = fst.getState(i);
          if (s.getId() == fst.getStartState().getId()) {
            continue;
          }
          if (fst.getSemiring().isNotZero(s.getFinalWeight()) || !omitZeroStates) {
            out.println(s.getId() + "\t" + s.getFinalWeight());
          }
        }
  
        MutableSymbolTable.InvertedSymbolTable inputIds = fst.getInputSymbols().invert();
        MutableSymbolTable.InvertedSymbolTable outputIds = fst.getOutputSymbols().invert();
        numStates = fst.getStateCount();
        for (int i = 0; i < numStates; i++) {
          State s = fst.getState(i);
          int numArcs = s.getArcCount();
          for (int j = 0; j < numArcs; j++) {
            Arc arc = s.getArc(j);
            String isym;
            String osym;
            if (useSymbolIdsInText) {
              isym = Integer.toString(arc.getIlabel());
              osym = Integer.toString(arc.getOlabel());
            } else {
              isym = inputIds.keyForId(arc.getIlabel());
              osym = outputIds.keyForId(arc.getOlabel());
            }
  
            out.println(s.getId() + "\t" + arc.getNextState().getId()
              + "\t" + isym + "\t" + osym + "\t"
              + arc.getWeight());
          }
        }
  
        out.close();
      } catch (IOException e) {
        throw Throwables.propagate(e);
      }
  
    }
docs: Exports an fst to the openfst text format
  
  @param fst      the fst to export
  @param filename the openfst's fst.txt filename