class Mytestjava (Mytestjava.java)
import java.io.*; import java.awt.*; import javax.swing.*; import java.util.StringTokenizer; import java.nio.CharBuffer; public class Mytestjava { static String[] array; static String output = ""; public static void main(String[] args) { File position; File text; String InFileName,OutFileName; int num; String inputstr; try{ InFileName = args[0]; StringTokenizer tokens = new StringTokenizer( InFileName, ".t"); position = new File(InFileName); OutFileName = tokens.nextToken() + ".w" + tokens.nextToken(); System.out.print("Input File Name:" + InFileName + "\n" ); System.out.print("Output to the File :" + OutFileName+ "\n" ); text = new File(OutFileName); } catch(Exception e){ System.out.print("Error:"+e); System.exit(1); position = new File(""); text = new File(""); } array = new String[11]; try{ BufferedReader input = new BufferedReader(new FileReader( position ) ); int i=0; inputstr= input.readLine(); while (inputstr != null) { array[i]= inputstr; output+=array[i]+"\n" ; System.out.println("Array("+i+")"+ array[i]); i=i+1; inputstr= input.readLine(); } input.close(); } catch(IOException IOException){ } try{ BufferedWriter output1 = new BufferedWriter(new FileWriter( text) ); output1.write(output); output1.flush(); } catch(IOException IOException){ } } } |
輸入檔案 930201.s01 內容:
1 2 3 4 5 6 8.4 9.3 0.2 7.9 3.4 |
執行結果:
D:\test2\mytest1\src>java Mytestjava 930201.s01 Input File Name:930201.s01 Output to the File :930201.ws01 Array(0)1 Array(1)2 Array(2)3 Array(3)4 Array(4)5 Array(5)6 Array(6)8.4 Array(7)9.3 Array(8)0.2 Array(9)7.9 Array(10)3.4 |
輸出檔案 930201.ws01 內容:
1 2 3 4 5 6 8.4 9.3 0.2 7.9 3.4 |
沒有留言:
張貼留言