package com.pps.test;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
public class Test {
public static void main(String[] args) throws IOException{
Test.readFileByLines("E:/sql.txt");
}
/**
* 以行为单位读取文件,常用于读面向行的格式化文件
*
* @param fileName
* 文件名
*/
public static String readFileByLines(String fileName) throws IOException {
StringBuffer fileContext = new StringBuffer("");
File file = new File(fileName);
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(file));
String tempString = null;
int line = 1;
// 一次读入一行,直到读入null为文件结束
while ((tempString = reader.readLine()) != null) {
// 显示行号
fileContext.append(line + ":" + tempString.toUpperCase() + "\n");
if(line==1){
System.out.println("StringBuffer sql = new StringBuffer(\" " + tempString.toUpperCase() + " \");");
}else{
System.out.println("sql.append(\" "+tempString.toUpperCase()+" \");");
}
line++;
}
System.out.println("return sql.toString();");
reader.close();
} catch (IOException e) {
throw e;
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
throw e;
}
}
}
return fileContext.toString();
}
}
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
public class Test {
public static void main(String[] args) throws IOException{
Test.readFileByLines("E:/sql.txt");
}
/**
* 以行为单位读取文件,常用于读面向行的格式化文件
*
* @param fileName
* 文件名
*/
public static String readFileByLines(String fileName) throws IOException {
StringBuffer fileContext = new StringBuffer("");
File file = new File(fileName);
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(file));
String tempString = null;
int line = 1;
// 一次读入一行,直到读入null为文件结束
while ((tempString = reader.readLine()) != null) {
// 显示行号
fileContext.append(line + ":" + tempString.toUpperCase() + "\n");
if(line==1){
System.out.println("StringBuffer sql = new StringBuffer(\" " + tempString.toUpperCase() + " \");");
}else{
System.out.println("sql.append(\" "+tempString.toUpperCase()+" \");");
}
line++;
}
System.out.println("return sql.toString();");
reader.close();
} catch (IOException e) {
throw e;
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
throw e;
}
}
}
return fileContext.toString();
}
}