给定一个数,求阶乘,然而这个数的阶乘的结果很大,只能使用 BigInteger 对象来储存

package biginteger;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.math.BigInteger;
class main{
    public static void main(String[] args) throws IOException {
        File file = new File("./src/biginteger/result.dat");
        if (!file.exists()){
            file.createNewFile();
        }
        FileWriter out = new FileWriter(file);
        BigInteger result = factor(50);
        String sum = result.toString();
        out.write(sum);
        out.close();
    }
    public static BigInteger factor(long n) {     //阶乘
        BigInteger sum = new BigInteger(String.valueOf(n));
        for (long i = 1; i < n; i++){
            sum = sum.multiply(BigInteger.valueOf(i));
        }
        return sum;
    }
}