437384801@163.com
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package addlinenumbers;
/**
*
* @author Administrator
*
*
*/
/* Import the Scanner class and all classes from java.io */
// Your code here
import java.io.*;
import java.util.Scanner;
public class AddLineNumbers {
public static void main( String [] args )
{
/* Declare variable identifiers to handle text data input from the file and count/increment the linenumber */
// Your code here
FileInputStream in;;Scanner s;
/* Start try block */
// Your code here
try{
/* Instantiate Scanner object for data input from file “dataInput.txt”. There should be no path specification as your input file should be located in your AddLineNumbers project folder */
// Your code here
in=new FileInputStream("dataInput.txt");
s=new Scanner(in);
/* Instantiate a FileOutputStream object for file “dataOutput.txt”. Do not specify a path. Your file will be created in the project folder by NetBeans */
// Your code here
FileOutputStream f=new FileOutputStream("dataOutput.txt");
/* Instantiate a PrintWriter object for writing data to your FileOutputStram object */
// Your code here
PrintWriter w=new PrintWriter (f);
/* Using a while loop control structure, read one line of data from input file, prepend the line number to data read from the file and output concatenated data to output file */
// Your code here
while(s.hasNext())
{
String line= s.nextLine();
w.append(line, 0,line.length());
}
/* Close files and output message indicating the file has been written */
// Your code here
w.close();
s.close();
/* End try block */
}
/* Code FileNotFoundException and IOException catch blocks. Call getMessage(), toString() and printStackTrace() methods on exception object thrown */
// Your code here
catch(FileNotFoundException e)
{e.getMessage();
e.printStackTrace();
}catch(IOException ex)
{
ex.printStackTrace();
}
}
}
晚上下班,有时间给你看看
ydq_jlf@163.com
1002127216@qq.com
lclado@sina.com,看看什么情况~~~
420943032@qq.com
哈哈 高分 还是有吸引力啊~~