Graphitic carbon nanocubes (GCNCs) were prepared by pyrolysis of ZIF-8 nanocubes. The GCNCs resemble the structure of N-doped graphite and exhibit a high photothermal conversion efficiency of 40.4%. In vitro tests demonstrate that the GCNCs are highly biocompatible and induce an effective photothermal therapy effect under 808 nm irradiation. Our study provides a facile strategy for preparing functional carbon nanomaterials of prescribed size, morphology, and porous structure for bioapplications.