安卓未能显示出结果 [英] android failed to show result

查看:90
本文介绍了安卓未能显示出结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面$ C C I用于在箱子SD卡中的文件。但它没有给任何有效的OUT输出。只显示世界您好......当创建的文件将显示消息,该文件将被存储?

Below code i used to crate a file in sdcard. but it not giving any valid out put. showing only the hello world...Where the "file created" message will be displayed and where the file will be stored?

包com.read;

package com.read;

进口java.io.FileOutputStream中;

import java.io.FileOutputStream;

进口android.app.Activity;
进口android.content.Context;
进口android.os.Bundle;

import android.app.Activity; import android.content.Context; import android.os.Bundle;

公共类读取扩展活动{
    / **当第一次创建活动调用。 * /
    @覆盖
    公共无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.main);

public class read extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);

    String FILENAME = "hello_file";
    String string = "hello world!";
    try{
    FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
    fos.write(string.getBytes());
    fos.close();
    }catch(Exception e){}

    System.out.println("File created");

}

}

推荐答案

使用这个方法,你想创建在手机的内部存储器中的文件。

Using this method you're trying to create a file in phone's internal memory.

只要使用这个code:

Just use this code:

FileOuputStream fos = new FileOutputStream( "/sdcard/" + FILENAME );

这会在你的SD卡的根文件夹中创建一个文件。

It will create a file in a root folder of your SD card.

这篇关于安卓未能显示出结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆