An effective synthetic route has been reported to prepare N/B co-doped hierarchical carbon nanofibers (NB-HCNFs) as free-standing electrodes for high-performance supercapacitors. Zeolitic imidazolate framework (ZIF-8) nanoparticles were embedded into polyacrylonitrile (PAN) through electrospinning to obtain PAN/ZIF-8 nanofibers. Tannic acid (TA) acted as a coating layer for PAN/ZIF-8 to generate hollow ZIF-8 core structures within the fiber and an intermediate to coordinate with 1,4-benzenediboronicacid (BDBA). After carbonization, the obtained flexible N/B co-doped hierarchical porous carbon nanofibers were used as free-standing electrodes for supercapacitors. Thus, unique nanostructure and the existence of heteroatoms could offer remarkably improved electrochemical properties with a high specific capacitance (288.2 F g−1 at a current density of 1 A g−1) and good cycling stability (96.9% capacitance retention over 8000 cycles at 10 A g−1). In addition, the NB-HCNFs films were assembled into symmetric supercapacitors, which displayed a high energy density and excellent stability (99.7% capacitance retention after 8000 cycles at 10 A g−1). The synthetic method might provide an effective and facile strategy to prepare a variety of hierarchical doped carbon nanomaterials for energy storage.