We investigated the electronic and magnetic properties of fully oxidized BaFeO3 thin films, which show ferromagnetic-insulating properties with cubic crystal structure, by hard x-ray photoemission spectroscopy (HAXPES), x-ray absorption spectroscopy (XAS) and soft x-ray magnetic circular dichroism (XMCD). We analyzed the results with configuration-interaction (CI) cluster-model calculations for Fe4+, which showed good agreement with the experimental results. We also studied SrFeO3 thin films, which have an Fe4+ ion helical magnetism in cubic crystal structure, but are metallic at all temperatures. We found that BaFeO3 thin films are insulating with large magnetization (2.1muB/formula unit) under ~ 1 T, using valence-band HAXPES and Fe 2p XMCD, which is consistent with the previously reported resistivity and magnetization measurements. Although Fe 2p core-level HAXPES and Fe 2p XAS spectra of BaFeO3 and SrFeO3 thin films are quite similar, we compared the insulating BaFeO3 to metallic SrFeO3 thin films with valence-band HAXPES. The CI cluster-model analysis indicates that the ground state of BaFeO3 is dominated by d5L (L: ligand hole) configuration due to the negative charge transfer energy, and that the band gap has significant O 2p character. We revealed that the differences of the electronic and magnetic properties between BaFeO3 and SrFeO3 arise from the differences in their lattice constants, through affecting the strength of hybridization and bandwidth.