The best and most advisable way to keep your files even after factory resetting is by storing your files and programs on the cloud. You can also use other external storage devices to ensure that your files are safe even after the whole process is over.