简单代码纪录-去除文本文件第一个空格前的的所有字符

MrLee2015-4-16 1311

刚在复制代码的时候有时候把行号也复制到了,一般转载的文章或者直接从别人网站复制过的的都有这个现象。简单点了几句代码。可以把文本文件第一个空格前的的所有字符全部去掉。。。
不多说,贴上代码喽!省的以后再写!
package com;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class DeleteStartNum {
	public DeleteStartNum() {
		// TODO Auto-generated constructor stub
		JFrame frame = new JFrame("top");
		frame.setAlwaysOnTop(true);
		frame.setVisible(true);
		frame.setLocationRelativeTo(null);
		String path = JOptionPane.showInputDialog(frame, "文件地址",
				"C:\\Users\\Administrator\\Desktop\\temp.txt");
		if (path != null && path.length() > 0) {
			File file = new File(path);
			try {
				FileInputStream fis = new FileInputStream(file);
				InputStreamReader in = new InputStreamReader(fis,
						Charset.forName("GBK"));
				BufferedReader reader = new BufferedReader(in);
				String line = reader.readLine();
				while (line != null) {
					line = line.trim();
					int nbsp = line.indexOf(" ");
					if (nbsp != -1)
						System.out.println(line.substring(nbsp + 1));
					else
						System.out.println(line);
					line = reader.readLine();
				}
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		frame.dispose();
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new DeleteStartNum();
	}
}

本文链接:https://www.it72.com/2221.htm

推荐阅读
最新回复 (0)
    返回