2013-12-12 4 views
-3

Java에서 줄 단위로 파일을 읽으려고합니다. 예를 들어 내가이 줄 번호를 기반으로 읽 이제줄 번호로 Java에서 줄 단위로 파일을 읽는 방법

Log points: 

1. We develop a project about Preventive Maintenance Checklist for Employees on PC/Tablet using Java. 
2. We here have check boxes for checking the list of works for quarterly, half yearly and annually. 
3. This tool is created to check the lists. 
4. This tool is created to make no human errors 
5. This tool is created using eclipse development tool. 
6. Eclipse is an IDE – Integrated development environment. 
7. Eclipse is a java development tool with many plug-ins and supports. 
8. We use WAMP server as database server which hosts the database connectivity. 
9. The database is created using the Mysql. Mysql is free source tool for creating database. 
10. The project has a user interface which is created using JSP –Java server pages. 
11. Jsp is used for user interface designing and it is compiled in java compiler. 
12. Servlets are server side scripting. Which accepts client side requests from the jsp and it connects with the business logic and gives the response. 
13. Our application runs in Apache tom cat server. It is free server developed and released by apache software foundation. 
14. This server is hosts the application and run. 
15. In our project we give request from the jsp and we give the defined values to the servlets which runs in the server. The servlets takes the response and gives the expected output. 
16. The values are stored in the database. And can be retrieved and deleted in future. 
17. This project gives the complete information and logs the information provided. 
18. We used MIRRA ,DNS, Sort and merge, profiler. 
19. We also logs the time starts and time ends and it schedules that way. 
20. We also logs the output, issues, action required etc. 

new.txt

new.txt 같은 파일이 있습니다. 그리고 그것을 새로운 파일에 쓰고 싶습니다. 예를 들어, 파일 f1.txt의 3-5 행 및 파일 3-6 f2.txt의 1-3 행. 나는 다른 파일에 글을 쓰는 것을 안다. 하지만 자바에서 어떻게 분할 해야할지 모르겠다.

BufferedReader br=new BufferedReader(new FileReader(file)); 

     while(br.readLine()!=null) 
     { 
     String s=br.readLine(); 


     counter++; 
     } 


     int size=counter/9; 

      System.out.println(counter); 

     for(int id=0;id<size;id++) 
     { 

      //how to split the files and read And from here no idea 
     } 
+0

LineNumberReader. – bmargulies

+0

코드를 편집했습니다. 도와주세요. – seenome

+0

Apache 공용 IO FileUtil 사용 http://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/FileUtils.html – Makky

답변

0

당신은 이것으로부터 약간의 아이디어를 얻을 수 있습니다. 이것은 좋은 해결책은 아니지만이 아이디어를 통해 얻을 수 있습니다.

Scanner scanner=new Scanner(new File("/home/ruchira/Test.txt")); 
FileWriter fileWriter1=new FileWriter(new File("/home/ruchira/1.txt")); 
// you will have to create more files. 
while (scanner.hasNextLine()){ 
    String line=scanner.nextLine(); 
    int lineNum=0; 
    try { 
     if(!line.equals("")){ 
      lineNum=Integer.parseInt(line.split("\\.")[0]); 
      if(lineNum>=1 && lineNum<=3){ // check for line numbers 
       fileWriter1.append(line) ; 
       fileWriter1.append("\n"); 
      } 
      // there will be more if conditions in your case. 
     } 

    }catch (NumberFormatException | IndexOutOfBoundsException e){ 

    } 

} 
fileWriter1.close(); 
관련 문제