File.Create(" Name.txt")。Dispose()在计算机上工作,但不在Android

时间:2017-09-20 21:05:39

标签: c# android file save

正如我所提到的,我尝试删除保存文件并在计算机上整理游戏,它完美无缺。但是在Android上,它既不会创建文件,也不会创建文件,但不会在其中写入任何内容。

以下是SaveFileManagement的代码:

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.UI;

public class onAppStart : MonoBehaviour {

    public Text moneyText;

    void Start () {
        if (!File.Exists("doubleMoney.txt"))
        {
            File.Create("doubleMoney").Dispose();
            System.IO.File.WriteAllText("doubleMoney.txt", "0");
        }

        if (!File.Exists("money.txt"))
        {
            File.Create("money").Dispose();
            System.IO.File.WriteAllText("money.txt", "2.5");
            double doubleMoney = Convert.ToDouble(System.IO.File.ReadAllText("money.txt"));
            float money = ToSingle(doubleMoney);
            moneyText.text = money.ToString() + "$";
        }
        else
        {
            double doubleMoney = Convert.ToDouble(System.IO.File.ReadAllText("money.txt"));
            float money = ToSingle(doubleMoney);
            moneyText.text = money.ToString() + "$";
        }
    }

    public static float ToSingle(double value)
    {
        return (float)value;
    }
}

1 个答案:

答案 0 :(得分:0)

您正在尝试创建" doubleMoney",但写入/检查" doubleMoney.txt"的存在。修复您的文件名以保持一致。