public class filewriter和bufferedwriter {
public static void main(String[] args) throws IOException{
// TODO 自动生成的方法存根
//分别使用 FileWriter 和 BufferedWriter
//往文件中写入 10万个随机数,比用时的多少。
FileWriter fileWriter = new FileWriter("C:\\Users\\33202\\Desktop\\bbb\\bbb.txt");
for(int i =0 ; i<100000;i++) {
fileWriter.write((int) Math.random());
}
fileWriter.flush();
fileWriter.close();
}
}
public static void main(String[] args) {
long startTime = System.currentTimeMillis(); // 获取程序开始时间
String fileName = "C:\\Users\\Administrator\\Desktop\\numbers.txt";
try {
// FileWriter writer = new FileWriter(fileName);
BufferedWriter writer = new BufferedWriter(new FileWriter(fileName));
Random random = new Random();
for (int i = 0; i < 100000; i++) {
int randomNumber = random.nextInt(100); // 生成0到99之间的随机数
writer.write(randomNumber + "\n"); // 写入文件并换行
}
writer.close();
System.out.println("随机数已写入文件。");
} catch (IOException e) {
System.out.println("写入文件时出错:" + e.getMessage());
}
long endTime = System.currentTimeMillis(); // 获取程序结束时间
long duration = endTime - startTime; // 计算程序运行时长
System.out.println("程序运行时长:" + duration + "毫秒");
}
https://developer.huawei.com/consumer/cn/service/hms/catalog/huaweiiap_oversea.html?page=hmssdk_huaweiiap_devprepare_oversea
按照文档一步步来,千万不要跳步骤,要不出问题不好排查
可能出问题的地方
在清单的application节点下增加APPID
<meta-data
android:name="com.huawei.hms.client.appid"
<!-- value的值“xxx”用实际申请的应用ID替换,来源于开发者联盟网站应用的服务详情。-->
android:value="appid=xxx">
</meta-data>
记住里面是appid=xxx而不是去掉xxx
可以使用以下代码向特定的文本文件中添加数字:
//先读取原本的文本内容
string path = Application.persistentDataPath + "/example.txt";
string content = File.ReadAllText(path);
//将要添加的数字转换为文本格式
int number = 123;
string numberStr = number.ToString();
//将数字添加到文本内容后面
content += numberStr;
//将修改后的文本内容写入文件
File.WriteAllText(path, content);
以上代码首先读取原本的文本内容,将要添加的数字转换为文本格式后,再将数字添加到文本内容后面,最后将修改后的文本内容写入文件。