package news;
import java.io.*;
public class Test11 {
private static BufferedReader br = null;
private static File file = null;
private static BufferedWriter bw = null;
public static void main(String[] args) {
String b = null;
//file = new File("D:\\abc.txt");
file = new File("C:\\Users\\ye\\Desktop\\news\\bb.txt");
System.out.println(file.getAbsolutePath());
//System.out.println(file.getPath());
String path = file.getAbsolutePath();
String[] sb = path.split("\\\\");
for (String string : sb) {
System.out.println(string);
}
if (!file.exists() != false) {
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
try {
bw = new BufferedWriter(new FileWriter(file));
FileReader fr = new FileReader("C:\\Users\\ye\\Desktop\\news\\aa.txt");
br = new BufferedReader(fr);
while ((b = br.readLine()) != null) {
b= new String(b.getBytes("utf-8"),"utf-8");
System.out.println(b);
bw.write(b);//输出字符串
bw.newLine();//换行
bw.flush();
}
} catch (Exception e) {
e.printStackTrace();
}finally {
try {
br.close();
//bw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
import java.io.*;
public class Test11 {
private static BufferedReader br = null;
private static File file = null;
private static BufferedWriter bw = null;
public static void main(String[] args) {
String b = null;
//file = new File("D:\\abc.txt");
file = new File("C:\\Users\\ye\\Desktop\\news\\bb.txt");
System.out.println(file.getAbsolutePath());
//System.out.println(file.getPath());
String path = file.getAbsolutePath();
String[] sb = path.split("\\\\");
for (String string : sb) {
System.out.println(string);
}
if (!file.exists() != false) {
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
try {
bw = new BufferedWriter(new FileWriter(file));
FileReader fr = new FileReader("C:\\Users\\ye\\Desktop\\news\\aa.txt");
br = new BufferedReader(fr);
while ((b = br.readLine()) != null) {
b= new String(b.getBytes("utf-8"),"utf-8");
System.out.println(b);
bw.write(b);//输出字符串
bw.newLine();//换行
bw.flush();
}
} catch (Exception e) {
e.printStackTrace();
}finally {
try {
br.close();
//bw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}