Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.os.Environment;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static void writeCSV(String phoneNo, String Message) {
        File root = Environment.getExternalStorageDirectory();
        File csvFile = new File(root, "/adspammer/log.csv");
        FileWriter writer = null;
        try {
            writer = new FileWriter(csvFile, true);

            DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd @ HH:mm:ss");
            Date date = new Date();
            System.out.println(dateFormat.format(date));

            writer.append(dateFormat.format(date).toString());
            writer.append(',');
            writer.append(phoneNo);
            writer.append(',');
            writer.append(Message);
            writer.append('\n');

            writer.flush();
            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}