创建和存储日志文件在设备上的机器人机器人、文件、设备、日志

由网友(帅 De.没人性)分享简介:我打算创建一个日志存储在执行应用程序的一些成果来自动执行应用程序的测试和后者在解析它使用了一块蟒蛇code和绘制的图表。I am planning to automate the testing of an application by creating a log to store some results of...

我打算创建一个日志存储在执行应用程序的一些成果来自动执行应用程序的测试和后者在解析它使用了一块蟒蛇code和绘制的图表。

I am planning to automate the testing of an application by creating a log to store some results of execution of the app and latter on parse it using a piece of python code and plot a graph.

该应用程序是指纹识别,即它收集的信息,例如MAC ID,RSS(:收到信号强度和排名(归RSS)关于周围环境的WiFi设备。因此,为了测试这个应用程序的WiFi我将不得不采取它位置和(手动截至目前)记录结果。所以logcat的不会达到目的。

The application is a WiFi fingerprinter i.e it collects info such as mac id, rss(recieved signal strength and rank(normalized rss) about the wifi devices in the surrounding environment. So to test this application I would have to take it to the location and record the results(as of now manually). So logcat wouldn't serve the purpose.

自动化要求 1.存储在日志中设备 通过USB 2.0连接到系统日志文件

Automation requires 1. Storing the log in the device 2. Access to the log file in the system through usb

日志文件的格式:

Snapshot: 1
Fingerprint: 1, Rank: 0.23424, Boolean: true
Fingerprint: 2, Rank: 0.42344, Boolean: false
Fingerprint: 3, Rank: 0.23425, Boolean: true

Snapshot: 2
Fingerprint: 1, Rank: 0.75654, Boolean: false
Fingerprint: 2, Rank: 0.23456, Boolean: true
Fingerprint: 3, Rank: 0.89423, Boolean: true 

................

现在我知道,基本上有三种途径进行永久存储(共享preFS不适合这种情况下是这样)。我试了内部存储,但即使设置文件的模式为 MODE_WORLD_READABLE 这是不可能后,read在使用文件设备文件资源管理器在Eclipse 。

Now I know there are basically 3 approaches for persistent storage(SharedPrefs wouldn't suit this scenario anyway). I tried Internal Storage, but even after setting the mode of the file as MODE_WORLD_READABLE it was impossible to read the file using Device File Explorer in Eclipse.

我还是谨慎使用外部存储器,用于存储日志。关于如何写一个文件在设备的USB任何教程有一定帮助。

I am still wary of using external storage for storing the log. Any tutorial on how to write to a file in usb of the device will definitely help.

我认为结构化的数据被存储以便使用SQLite用于存储。但数据之间这种建立很多不必要的关系(外国和国内)使其复杂。如果周围有没有办法,然后这里是龙

I thought of structuring the data to be stored so as to use SQLite for storage. But this establishing many unnecessary relations(foreign and domestic) between data and make it complex. If there is no way around, then here be dragons.

基本上我想要写一个文件(更容易我想)在设备和后者由通过USB连接到它读取它在我的系统。如何做到这一点任何帮助将是非常美联社preciated。

Basically I want to write to a file(easier I suppose) in the device and latter on read it in my system by connecting to it via usb. Any help on how to do it would be much appreciated.

推荐答案

警惕与否,外部存储仍可能是唯一的出路。如果没有在设备上root权限,你不能真正得到的东西内部,除非你会好起来的设备上的应用程序中读取。该文档提供了在哪里创建外部文件pretty的坚实准则,如果你使用的是API级别8或更高版本,也有一些额外的功能,都可以使用。我敢肯定,你知道这个网页,但在这里它是无论如何:的http://developer.android.com/guide/topics/data/data-storage.html#filesExternal

Wary or not, External Storage still may be the only way to go. Without root access on the device, you can't really get at anything "Internal" unless you're going to be okay with reading within an application on the device. The docs provide pretty solid guidelines for where to create external files, and if you are using API Level 8 or higher, there are a couple of extra functions that can be used. I'm sure you know this page, but here it is anyway: http://developer.android.com/guide/topics/data/data-storage.html#filesExternal

如果您需要IO例如code的任何文件的...我想我能挖出一些了......

If you're in need of any file io example code... I think I could dig some up...

编辑 - 我会按照上述文档的指导方针,以先确认存储的状态开始。我很遗憾没有与附加在Java中的文件中的任何经验,所以别人一定会更有资格回答。这不包括追加,但我有我的个人应用程序的一个看起来像这样的备份程序。

EDIT - I would start by following the guidelines in the above docs to first confirm the state of the storage. I unfortunately don't have any experience with appending a file in Java, so someone else would definitely be more qualified to answer. This doesn't cover appending, but I have a backup routine in one of my personal apps that looks something like this.

    File backupPath = Environment.getExternalStorageDirectory();

    backupPath = new File(backupPath.getPath() + "/Android/data/com.maximusdev.bankrecord/files");

    if(!backupPath.exists()){
        backupPath.mkdirs();
    }

    FileOutputStream fos;
    try {
        fos = new FileOutputStream(backupPath.getPath() + "/recordsbackup.txt");

        if(okaytowrite){
            for(int i = 0; i < count; ++i){
                entry = adapter.getItem(i);
                fos.write(entry.toString().getBytes());
                fos.write("n".getBytes());
                fos.write(String.valueOf(entry.dateTime).getBytes());
                fos.write("n".getBytes());
                fos.write(String.valueOf(entry.sign).getBytes());
                fos.write("n".getBytes());
                fos.write(String.valueOf(entry.cleared).getBytes());
                fos.write("n".getBytes());
                fos.write(String.valueOf(entry.transDate).getBytes());
                fos.write("n".getBytes());
                fos.write(entry.category.getBytes());
                fos.write("n".getBytes());
            }
        }
        fos.close();

        Toast.makeText(this, "Backup Complete", Toast.LENGTH_SHORT).show();

    } catch (FileNotFoundException e) {

        e.printStackTrace();

        AlertDialog.Builder delmessagebuilder = new AlertDialog.Builder(this);

        delmessagebuilder.setCancelable(false);

        delmessagebuilder.setMessage("File Access Error");

        delmessagebuilder.setNeutralButton("Okay", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                dialog.dismiss();
            }
        });

        delmessagebuilder.create().show();

    } catch (IOException e) {

        e.printStackTrace();

        AlertDialog.Builder delmessagebuilder = new AlertDialog.Builder(this);

        delmessagebuilder.setCancelable(false);

        delmessagebuilder.setMessage("File Access Error");

        delmessagebuilder.setNeutralButton("Okay", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                dialog.dismiss();
            }
        });

        delmessagebuilder.create().show();
    }

在我准备写,我拉着一个自定义对象(入)出一个ArrayAdapter(适配器)和转换领域valuse为字符串并使用的GetBytes()传递给FileOutputStream中写功能。我做了一些研究,也有不少其他的选项文件使用Java语言编写/安卓...的FileWriter的班实例,因此它承担进一步的研究。

Once I'm ready to write, I'm pulling a custom object (entry) out of an ArrayAdapter (adapter) and converting field valuse to strings and using getBytes() to pass to the FileOutputStream write function. I've done some research and there are quite a few other options for file writing in Java/Android... the FileWriter Class for instance, so it bears further research.

阅读全文

相关推荐

最新文章