Assets to read txt files in the folder

2010-12-23  来源:本站原创  分类:Mobile  人气:116 

package com.example.ReadAsset;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import java.io.IOException;
import java.io.InputStream;

public class ReadAsset extends Activity {
        @Override
        protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.read_asset);

                try {
//Return an AssetManager instance for your application's package
                        InputStream is = getAssets().open("index.txt");
                        int size = is.available();

                        // Read the entire asset into a local byte buffer.
                        byte[] buffer = new byte[size];
                        is.read(buffer);
                        is.close();

                        // Convert the buffer into a string.
                        String text = new String(buffer, "GB2312");

                        // Finally stick the string into the text view.
                        TextView tv = (TextView) findViewById(R.id.text);
                        tv.setText(text);
                } catch (IOException e) {
                        // Should never happen!
                        throw new RuntimeException(e);
                }
        }
}

main.xml

<?xml version="1.0" encoding="utf-8"?>
<ScrollView android:layout_width="fill_parent"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_height="fill_parent" android:paddingTop="50dip">
        <TextView android:id="@+id/text" android:layout_width="fill_parent"
                android:layout_height="wrap_content" android:textStyle="normal" />
</ScrollView>

. And then create a new assets in the project folder inside, casually put a index.txt file in which to run
Ctrl + F11 can be tested;

http://edison-cool911.javaeye.com/blog/695145

相关文章
  • Assets to read txt files in the folder 2010-12-23

    package com.example.ReadAsset; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; import java.io.IOException; import java.io.InputStream; public class ReadAsset extends Activity { @Override protected void onCreate(

  • [Solaris] How to exclude files under the folder tar command 2010-08-16

    [Solaris] How to exclude files under the folder tar command Today, dealing with the affairs of Chongqing encountered a problem: in solaris how to use the tar command to package exclude folders. Wang Wei was finally consulted to resolve, and out to sh

  • LaunchDirectory get the project directory of such files in the folder 2010-06-14

    package com.evangelsoft.econnect.util; import java.io.File; /** * This class is the project directory for the files in the folder * @author huali * */ public class LaunchDirectory { private static String dir = null; public LaunchDirectory() { } //Get

  • Lists all the files under the folder 2010-07-27

    Lists all the files under the folder, use the recursive package com.icss.test; import java.util.*; import java.io.File; public class FileReaderTest { public void read(String ss){ File file=new File(ss); String[] str=file.list(); // List ll=Arrays.asL

  • ubuntu open the. TXT files garbled 2010-09-25

    To open in ubuntu. TXT files appear garbled in Chinese and in this way to find a solution: Input terminal gconf-editor gconf-edit redeployment PS: you can enter gconf-editor, do not need to add in front of Sudo In turn point to open apps-> gedit-2->

  • Solve ubuntu open. TXT files garbled problem 2011-06-15

    To open in ubuntu. TXT files, the Chinese appear garbled, to find a solution in this way: Input terminal gconf-editor bring up the gconf-edit PS: you can enter gconf-editor, not the front plus Sudo Followed by opening the apps-> gedit-2-> preference

  • Linux command line statistics and current number of files under the folder 2011-07-25

    Statistics of a number of files under the folder ls-l | grep "^-"| wc-l Statistics of a number of directory folder ls-l | grep "^ d" | wc-l Statistics the number of files under the folder, including sub-folders inside. ls-lR | grep &qu

  • C / C + + to read all the files under the folder (reprint not tested) 2010-04-09

    #include "stdlib.h" #include "direct.h" #include "string.h" #include "io.h" #include "stdio.h" #include "iostream.h" class CBrowseDir { protected: // For initial directory, absolute paths, to '\'

  • Traverse all the files under the folder, edit, delete 2010-07-13

    Example 1, <?php /* Traverse Folder ; Features :(a) To delete files (b) Editable text, page file (c) Folder can be deleted, provided that the folder is empty (d) Can create files, folders, , Modify the folder name ; */ $path=$DOCUMENT_ROOT; $path=str

  • fedora12 gedit open system copied from the xp txt files appear garbled Chinese 2011-02-12

    Open gedit copied from the xp systems in the emergence of Chinese garbled txt file 1 In the editor open: File -> open 2 Click on the following: Character Encoding -> Add or Remove 3 Add Chinese GBK, and then open the file to display Chinese. vim to

  • View txt files under Linux 2011-02-20

    GEDIT gedit is a GNOME desktop environment, UTF-8 compatible text editor. It uses GTK + written in, so it is very easy to use, has good syntax highlighting, support for Chinese good support including gb2312, gbk, including a variety of character enco

  • Batch files - move the folder where the database backup files to a network path on the map 2011-06-14

    Batch file written as follows: @ Echo off :: Set the database backup folder path set current = E: \ test :: Map path to create the folder (taking the current system time, such as 2011-06-14), z is the path mapped md Z: \% date: ~ 0,10% :: Traverse th

  • How do I move all files from one folder to another 2015-02-23

    To do so, Open a terminal and execute this command: mv -v ~/Downloads/* ~/Videos/ It will move all the files and folders from Downloads folder to Videos folder. To Move all files, but not folders: But, If you are interested to move all files (but not

  • Copy all the files in the folder to the same directory 2010-03-29

    /** * Recursive loops through all of the folder, and copy the file */ private static void travelAndCopyFile(File root) { if (root.isFile()) { File distFile = new File(DIST_FOLDER + "/" + root.getName()); if (distFile.exists()) { distFile.delete(

  • [Change] linux statistics the number of files in a folder 2010-03-11

    The first method: ls-l | grep "^-"| wc-l ls-l long list of output files in the directory information (note that the document, different from the file may be directory, links, equipment, documents, etc.). If the ls-lR | grep "^-"| wc-l

  • Traverse all the files under the folder and subfolders 2010-04-23

    function my_scandir($dir) { $files = array(); if ( $handle = opendir($dir) ) { while ( ($file = readdir($handle)) !== false ) { if ( $file != ".." && $file != "." ) { if ( is_dir($dir . "/" . $file) ) { $files[$file]

  • A list of all files under the folder 2010-05-31

    This means simple, not to say, direct look at the code it! 1, auxiliary classes. Two FileFilter, a file filter, a directory filter public class FileFilter implements java.io.FileFilter { public boolean accept(File pathname) { if(pathname.isFile()) {

  • Get all the files under the folder the file name 2010-07-13

    dir c: \ sample / b> filelist.txt

  • java data synchronization processing txt files 2010-09-08

    txt file java data synchronization processing requirements: txt file the first line is the last line is the end begin begin end of each line of data with the "|" separate txt file about 30 million lines, 20M about the size of the treatment: I de

  • Linux to add all the files under the folder execute permissions 2011-07-06

    chmod-R 755 bin / / Bin is the folder name to be added.