简体   繁体   English

如何使用NeoMAD在指定文件夹中创建和写入文本文件

[英]how to create and write in a text file on specified folder using NeoMAD

I have a requirement to create a text file on specified folder and write the data in it 我需要在指定的文件夹上创建一个文本文件并在其中写入数据

i try this but it doesn't work : 我尝试这样做,但不起作用:

    file = new File(FileStorage.getPrivateDir(), "data");
    if (!file.exists()) {
        file.mkdirs();
    }else{
        fw=new  FileOutputStream(file);
        TextLabel sh=(TextLabel)findView(Res.id.ShFile);
        Person person;
        for(int i=0;i<persons.size();i++){
            person=(Person) persons.elementAt(i);
            sh.setText(person.getName()+" "+person.getNumberPhone());
            fw.write(Res.id.ShFile);  //public void write (int b)
        }

Is there any example which will help me? 有什么例子对我有帮助吗?

What do you want to achieve ? 您想实现什么? Serialize a Person object into a file ? 将Person对象序列化为文件?

File and FileOutputStream classes are the same as in JDK, but you need to serialize your data object by yourself, with DataOutputStream for example. File和FileOutputStream类与JDK中的类相同,但是您需要自己自己序列化数据对象,例如,使用DataOutputStream。 Something like this : 像这样的东西:

File file = new File(FileStorage.getPrivateDir(), "data");
DataOutputStream personStream = new DataOutputStream(new FileOutputStream(file));
personStream.writeUTF(person.getName());
personStream.writeInt(person.getAge());
personStream.flush();
personStream.close();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在NeoMAD项目中使用java.util.Iterator时出错 - Error when using java.util.Iterator in a NeoMAD project 如何使用NeoMAD在Mac Tiger上编译我的iOS应用程序? - How can I compile my application for iOS on Mac Tiger with NeoMAD? 如何部署NeoMAD应用程序并在iPhone设备上进行调试? - How can I deploy a NeoMAD application and debug it on an iPhone device? 带有拖放组件的NeoMAD应用程序UI设计 - NeoMAD application UI design with drag and drop components 如何为使用KaiOS的手机创建应用程序? - How to create apps for mobiles which are using KaiOS? 如何使用VS2010创建智能设备应用程序 - How to create Smart Device application using VS2010 新建Flutter App的文件夹和文件说明? - Folder and file explanation of newly created Flutter App? 如何使用PhoneGap和HTML Editor创建一个简单的应用程序但不使用Eclipse? - How to create a simple app using PhoneGap and HTML Editor but without using Eclipse? 如何从列表中更新 flutter 中的文本 - How to update the Text in flutter from List 如何使用 Firestore 创建基于位置的时间线 - How to create location-based timelines with Firestore
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM