import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;public class OprationTXT { public OprationTXT(String name){
File filename = new File(name);
if(!filename.exists()){
try {
filename.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
*
* @param filename
* @param context
*/
public static void writeTxtFile(String filename,String context){
RandomAccessFile raf = null;
try {
raf = new RandomAccessFile(filename,"rw");
// raf.writeBytes(context);
//raf.writeUTF(context);
raf.write(context.getBytes());
//raf.writeChars(context);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
if(raf != null){
try {
raf.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
public static void main(String args[]){
for(int i = 5 ; i <=62 ; i++){
StringBuffer sb = new StringBuffer();
String filename = "D:/安装软件/"+ i +".bat";
OprationTXT txt = new OprationTXT(filename);
sb.append("@echo off ")
.append("\n")
.append("cls ")
.append("\n")
.append("color 0A ")
.append("\n")
.append("Echo \u002A\u002A\u002A\u002A\u002A\u002A\u002A\u002A\u002A\u002A\u002A\u002A ")
.append("\n")
.append("Echo 正在修改IP地址和DNS服务器地址,请耐心等待………… ")
.append("\n")
.append("Echo \u002A\u002A\u002A\u002A\u002A\u002A\u002A\u002A\u002A ")
.append("\n")
.append("cmd /c netsh interface ip set address name=\"本地连接\" source=static addr=172.16.1.")
.append(i)
.append(" mask=255.255.255.192 gateway=172.16.1.1 gwmetric=1 ")
.append("\n")
.append("ipconfig /all ")
.append("\n")
.append("Echo \u002A\u002A\u002A\u002A\u002A\u002A\u002A\u002A\u002A\u002A ")
.append("\n")
.append("Echo OK!!已修改成功!请按任意键继续………… Echo 谢谢您的使用!太极制作 ")
.append("\n")
.append("Echo \u002A\u002A\u002A\u002A\u002A\u002A\u002A\u002A\u002A\u002A ")
.append("\n")
.append("Pause");
txt.writeTxtFile(filename, sb.toString());
}
}
}
'IP地址和DNS服务器地址' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
'face' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
'*******' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
'氚慈我饧绦?Echo' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
**********
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;public class OprationTxt { public OprationTxt(String name){
File filename = new File(name);
if(!filename.exists()){
try {
filename.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
*
* @param filename
* @param context
*/
public static void writeTxtFile(String filename,String context){
RandomAccessFile raf = null;
try {
raf = new RandomAccessFile(filename,"rw");
// raf.writeBytes(context);
//raf.writeUTF(context);
raf.write(context.getBytes("ISO8859-1"));
//raf.writeChars(context);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
if(raf != null){
try {
raf.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
public static void main(String args[]){
for(int i = 0 ; i <1 ; i++){
StringBuffer sb = new StringBuffer();
String filename = "D:/"+ i +".bat";
OprationTxt txt = new OprationTxt(filename);
sb.append("@echo off ")
.append("\n")
.append("cls ")
.append("\n")
.append("color 0A ")
.append("\n")
.append("Echo ******************")
.append("Echo \u002A\u002A\u002A\u002A\u002A\u002A\u002A\u002A\u002A\u002A\u002A\u002A ")
.append("\n")
.append("Echo \u6b63\u5728\u4fee\u6539IP\u5730\u5740\u548cDNS\u670d\u52a1\u5668\u5730\u5740,\u8bf7\u8010\u5fc3\u7b49\u5f85\u2026\u2026\u2026\u2026")
.append("\n")
.append("Echo \u002A\u002A\u002A\u002A\u002A\u002A\u002A\u002A\u002A ")
.append("\n")
.append("cmd /c netsh interface ip set address name=\"本地连接\" source=static addr=172.16.1.")
.append(i)
.append(" mask=255.255.255.192 gateway=172.16.1.1 gwmetric=1 ")
.append("\n")
.append("ipconfig /all ")
.append("\n")
.append("Echo \u002A\u002A\u002A\u002A\u002A\u002A\u002A\u002A\u002A\u002A ")
.append("\n")
.append("Echo OK\uff01\uff01\u5df2\u4fee\u6539\u6210\u529f\uff01\u8bf7\u6309\u4efb\u610f\u952e\u7ee7\u7eed\u2026\u2026\u2026\u2026 Echo \u8c22\u8c22\u60a8\u7684\u4f7f\u7528\uff01\u592a\u6781\u5236\u4f5c ")
.append("\n")
.append("Echo \u002A\u002A\u002A\u002A\u002A\u002A\u002A\u002A\u002A\u002A ")
.append("\n") .append("Pause &");
txt.writeTxtFile(filename, sb.toString());
}
}
}
english
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.Set;public class OprationTxt { public OprationTxt(String name){
File filename = new File(name);
if(!filename.exists()){
try {
filename.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
*
* @param filename
* @param context
*/
public static void writeTxtFile(String filename,String context){
FileOutputStream raf = null;
try {
raf = new FileOutputStream(filename);
// raf.writeBytes(context);
//raf.writeUTF(context);
raf.write(context.getBytes());
//raf.writeChars(context);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
if(raf != null){
try {
raf.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
public static void main(String args[]){
for(int i = 0 ; i <1 ; i++){
StringBuffer sb = new StringBuffer();
String filename = "D:/"+ i +".bat";
OprationTxt txt = new OprationTxt(filename);
sb.append("@echo off ")
.append(System.getProperty("line.separator"))
.append("cls")
.append(System.getProperty("line.separator"))
.append("color 0A")
.append(System.getProperty("line.separator"))
.append("Echo ******************")
.append(System.getProperty("line.separator"))
.append("echo \u6b63\u5728\u4fee\u6539IP\u5730\u5740\u548cDNS\u670d\u52a1\u5668\u5730\u5740,\u8bf7\u8010\u5fc3\u7b49\u5f85...")
.append(System.getProperty("line.separator"))
.append("echo ******************")
.append(System.getProperty("line.separator"))
.append("cmd /c netsh interface ip set address name=\"本地连接\" source=static addr=172.16.1.22." + (i+100))
.append(" mask=255.255.255.192 gateway=172.16.1.1 gwmetric=1")
.append(System.getProperty("line.separator"))
.append("ipconfig/all")
.append(System.getProperty("line.separator"))
.append("echo *******************")
.append(System.getProperty("line.separator"))
.append("echo ok 已经修改完成,请按任意键继续...")
.append(System.getProperty("line.separator"))
.append("echo *******************")
.append(System.getProperty("line.separator"))
.append("Pause &");
txt.writeTxtFile(filename, sb.toString());
}
}
}
你先看看你输出的那个文件对不对,用记事本打开。