Help us understand the problem. What is going on with this article?

vmg形式のファイルをeml形式で出力するjava

More than 3 years have passed since last update.

eml形式にするためのメッセージ単位のタグの間をファイルに書き出すだけの、
単純なもの。作った経緯は以下のページ参照。
Androidスマホのキャリアメールを取り出す方法

vmgは複数のメッセージデータがタグに囲まれて入っている。タグに関しては、以下を参考にした。
PowerShell で VMG ファイルを変換してエクセルで読む

import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.FileNotFoundException;

class vmg2Eml{
    public static void main(String args[]){
                String input_maildata_filename;
       if(args.length <= 0){
            System.out.println("コマンドラインにてファイル名を");
                        return;
        } else {
                    input_maildata_filename = args[0];
        }
        try{
                        int line_number = 0;
            File file = new File(input_maildata_filename);

                        if (!file.exists()){
                            System.out.println("ファイルはありません");
                            return;
                        }

                        FileInputStream FIS = new FileInputStream(file);
                        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(FIS,"UTF-8"));
                        String data;
                        String strBegin = "BEGIN:VBODY";
                        String strEnd = "END:VBODY";
                        Boolean Has2Write = false;
                        int mail_number = 0;

                        PrintWriter printwriter = null;
                        FileOutputStream FOS2write = null;

                        while ((data = bufferedReader.readLine()) != null) {
                            int isBegin = data.indexOf(strBegin);
                            int isEnd = data.indexOf(strEnd);

                            if(isBegin != -1){
                                Has2Write = true;
                                data = bufferedReader.readLine();
                                mail_number++;
                                String filename2write = String.format("%05d",mail_number) + ".eml";
                                File file2write = new File(filename2write);
                                FOS2write = new FileOutputStream(file2write);
                                printwriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(FOS2write,"UTF-8")));
                            }

                            if(isEnd != -1){
                                Has2Write = false;
                                printwriter.close();
                            }

                            if(printwriter != null && Has2Write){
                                printwriter.println(data);
                            }
                        }

            bufferedReader.close();

        }catch(FileNotFoundException e){
            System.out.println(e);
        }catch(IOException e){
            System.out.println(e);
        }
    }
}

//System.out.println(data);

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした