Java 读写文件 字符分隔
前一段时间因为需要帮别人写了简单的字符串分隔的java小程序,尽管最后没用上,但是作为练习还是不错的。
需求:对于像如下的字符创将其分隔为两列,这样就可以直接粘贴的Excel中各自列,否则一个一个分隔会耗费很多时间。
16 bit microcomputer 16 位微型计算机
3 d distribution 三维分布
4 bit slice processor 4位片处理机
5 reference 5伏基准电压源
a d converter 模拟数字转换器模数转换器
abbreviated code 缓冲存储器
abbreviated dialing 快速呼叫
aberration 象差
abnormal glow discharge 异常辉光放电
abnormal reflections 异常反射
abrasion 磨耗
abrasive 磨料
abrasive dust 磨粉
abrasive jet machining 磨料喷射加工
abrasive jet trimming 磨料喷射蝶
abrasive paste 磨蚀剂
abrasive trimming 研磨蝶
基本思路:按行读取文件,对于每行的字符串从后面找第一个空格,因为汉字一般是连在一起的(对以个别的有数字的暂时不管,分解完成后在手工做这些少数的问题)。从后面的第一个空格分开,将两个子字符串各自写入单独的文件。
代码如下:import java.io.*;
public class MainHT {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
if (args.length == 1) {
MainHT mainHT = new MainHT();
mainHT.ReadFile(args[0]);
}
else{
System.out.println("Usage fileName");
}
}
public void ReadFile(String fileNameandPath)
{
String record = null;
int recCount = 0;
try {
FileReader fr = new FileReader(fileNameandPath);
BufferedReader br = new BufferedReader(fr);
record = new String();
FileWriter fw1 = new FileWriter("one.txt");
PrintWriter pw1= new PrintWriter(fw1);
FileWriter fw2 = new FileWriter("two.txt");
PrintWriter pw2= new PrintWriter(fw2);
while ((record = br.readLine()) != null) {
recCount++;
System.out.print
相关文档:
String转Character数组,用Character的isDigit和isLetter函数去判断。
public static boolean isNumeric(String str) {
for (int i = str.length(); i = 0;) {
if (!Character.isDigit(str.charAt(i))) {
return false;
}
}
return true;
}
public static boolean isNumeric(String str) {
Pattern patt ......
public class Foo {
static void operate(StringBuffer x,StringBuffer y){
x.append(y);
y=x;
}
public static void main(String args[]){
StringBuffer a = new StringBuffer("A");
StringBuffer b = new StringBuffer("B");
& ......
java回调机制
回调概念:
软件模块之间总是存在着一定的接口,从调用方式上,可以把他们分为三类:同步调用、回调和异步调用。同步调用是一种阻塞式调用,调用方要等待对方执行完毕才返回,它是一种单向调用;回调是一种双向调用模式,也就是说,被调用方在接口被调用时也会调用对方的接口;异步调用是一种类似 ......
我使用URL类来访问FTP服务器,当地址中没有中文时没有问题,但是
当ftp中的文件夹有中文时,就无法访问了,我试过encoder和decoder类,都不行,有什么解决方法么?
URL now = new URL("ftp://202.204.208.124/软件/");
......
某些网站允许软件开发社团通过发布开发者指南、白皮书、FAQs【常见问题解答】和源代码以实现信息的共享。随着信息量的增长,和几个开发者贡献出自己的知识库,于是网站提供搜索引擎来搜索站点上现有的所有信息。虽然这些搜索引擎对文本文件的搜索可以做的很好,但对开发者搜索源代码做了比较严格的限制。搜索引擎认为源代码 ......