1\GetSourceFileLineNo.java
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
public class GetSourceFileLineNo{
public static void main(String[] args) {
getLimitRecord("./result.txt");
}
public static void getLimitRecord(String filePath){
BufferedReader br = null;
String tempStr = "";
int count = 0;
int allLineOfFile = getSourceFileLineNo(filePath);
try{
br = new BufferedReader(new FileReader(new File(filePath)));
while((tempStr=br.readLine())!=null){
if((allLineOfFile - count++)<=10){
System.out.println(tempStr);
}
}
}catch(IOException e){
System.out.println("没有该文件或目录");
e.printStackTrace();
}finally{
try{
br.close();
}catch(IOException e){
System.out.println("关闭以前关闭的流无效~!");
e.printStackTrace();
}
}
}
//Gets all lines of file
public static int getSourceFileLineNo(String filePath){
BufferedReader br = null ;
String tempStr = "";
int count = 0;
try{
br = new BufferedReader(new FileReader(new File(filePath)));
while((tempStr=br.readLine())!=null){
count ++;
}
}catch(IOException fnf){
System.out.println("没有该文件或目录");
fnf.printStackTrace();
}finally{
try{
br.close();
}catch(IOException e){
System.out.println("关闭以前关闭的流无效~!");
e.printStackTrace();
}
}
return count;
}
}
2\MobileRandomNum.java
import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
public class MobileRandomNum {
public static void main(String[] args) {
String channelName = channelName();
System.out.println(channelName);
System.out.println(startMobileNo() + "-" + endMobileNo());
}
public static int startMobileNo(){
int[] mobileStart = {139,138,137,136,135,134,159,158,157,150,151,152,188,130,131,132,156,155,133,153,189,180,177,176};
Random r = new Random();
ArrayList<Integer> mobileList = new ArrayList<Integer>();
for(int i = 0;i<mobileStart.length;i++){
mobileList.add(mobileStart[i]);
}
return mobileList.get(r.nextInt(mobileList.size()));
}
public static String endMobileNo(){
Random r = new Random();
String temp = "";
for(int i=0;i<8;i++){
if(i==4){
temp += "-";
}
temp += r.nextInt(10);
}
return temp;
}
public static String channelName(){
//System.out.println("请输入渠道:1.蚂蚁开户;2.常规开户;3.保单开户;4.融资融券预开户...");
Scanner scan = new Scanner(System.in);
int input_result = scan.nextInt();
String is_result = "";
// String is_result = String.valueOf(scan.nextInt());
switch(input_result){
case 1:
is_result = "蚂蚁开户";
break;
case 2:
is_result = "常规开户";
break;
case 3:
is_result = "保单开户";
break;
case 4:
is_result = "融资融券预开户";
break;
default:
is_result = "其他";
}
return is_result;
}
}
3\Test.java
import java.util.Scanner;
public class Test{
public static void main(String[] args){
Scanner can = new Scanner(System.in);
String strClass = String.valueOf(can.nextInt());
System.out.println(strClass.getClass().toString());
}
}
4\批处理文件内容如下mobileno.bat
@echo off
echo "最近的历史记录~:"
javac -encoding utf8 "D:\randomMobileNo\GetSourceFileLineNo.java"
cd "D:\randomMobileNo\"
for /f "delims=" %%i in ('java GetSourceFileLineNo') do (
echo %%i
)
:1
echo "请输入渠道:1.蚂蚁开户;2.常规开户;3.保单开户;4.融资融券预开户;5.其他..."
javac -encoding utf8 "D:\randomMobileNo\MobileRandomNum.java"
cd "D:\randomMobileNo\"
for /f "delims=" %%k in ('java MobileRandomNum') do (
echo %%k
echo "%%k" -- %date:~0,10% %time:~0,8%>> result.txt
)
pause
goto 1
5、执行结果写入result.txt
"蚂蚁开户" -- 2017-08-14 17:50:04
"152-9299-6752" -- 2017-08-14 17:50:04
"常规开户" -- 2017-08-14 17:50:36
"180-5163-8699" -- 2017-08-14 17:50:36
"蚂蚁开户" -- 2017-08-14 17:50:57
"159-1756-7043" -- 2017-08-14 17:50:57
"保单开户" -- 2017-08-14 17:51:01
"133-2187-4830" -- 2017-08-14 17:51:01
"融资融券预开户" -- 2017-08-14 17:51:08
"152-5487-5729" -- 2017-08-14 17:51:08
"蚂蚁开户" -- 2017-08-15 15:18:17
"157-5977-0146" -- 2017-08-15 15:18:17
"蚂蚁开户" -- 2017-08-14 17:50:30
"153-5129-9942" -- 2017-08-14 17:50:30
"蚂蚁开户" -- 2017-08-15 15:37:04
"188-5156-5391" -- 2017-08-15 15:37:04
"蚂蚁开户" -- 2017-08-15 15:37:25
"132-5877-3524" -- 2017-08-15 15:37:25
"常规开户" -- 2017-08-15 15:37:28
"151-4552-4644" -- 2017-08-15 15:37:28
"保单开户" -- 2017-08-15 15:37:31
"189-0328-0107" -- 2017-08-15 15:37:31