Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.io.File;

import java.io.RandomAccessFile;

import android.content.Context;

public class Main {
    public static void WriteTxtFile(Context context, String strcontent) {

        String strContent = strcontent + "\n";
        try {
            File file = new File(context.getCacheDir() + File.separator + "wanjia.txt");
            if (!file.exists()) {
                file.createNewFile();
            }
            RandomAccessFile raf = new RandomAccessFile(file, "rw");
            raf.seek(file.length());
            raf.write(strContent.getBytes());
            raf.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}