Advertisement
Guest User

Untitled

a guest
Sep 13th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.43 KB | None | 0 0
  1. import java.io.*;
  2. public class Main {
  3.  
  4. public Main() {
  5. File directory = new File("C:/Documents and Settings/Administrator/Desktop/Deadlypkers/Data/characters/");
  6. String[] allFiles = directory.list();
  7. if (allFiles == null) {
  8. System.out.println("No such directory");//brkownz
  9. return;
  10. }
  11. for (int file = 0; file < allFiles.length; file++) {
  12. File f = new File("C:/Documents and Settings/Administrator/Desktop/Deadlypkers/Data/characters/"+allFiles[file]+"/");
  13. System.out.println(f);
  14. FileInputStream fs = null;
  15. InputStreamReader in = null;
  16. BufferedReader br = null;
  17.  
  18. String textinLine;
  19. StringBuffer sb = new StringBuffer();
  20. String newLine = System.getProperty("line.separator");
  21. try {
  22.  
  23. fs = new FileInputStream(f);
  24. in = new InputStreamReader(fs);
  25. br = new BufferedReader(in);
  26.  
  27. while(true) {
  28. textinLine=br.readLine();
  29. if(textinLine==null)
  30. break;
  31. sb.append(textinLine);
  32. sb.append(newLine);
  33. }
  34.  
  35. int textBeginFishing = sb.indexOf("character-skill = 7");
  36. int textEndFishing = sb.indexOf("character-skill = 8");
  37. if (textBeginFishing == -1 || textEndFishing == -1) {
  38. System.out.println("Skipped the file: "+allFiles[file]);
  39. fs.close();
  40. in.close();
  41. br.close();
  42. continue;
  43. }
  44. String toChangeFishing = "character-skill = 7 1 0"+newLine;
  45.  
  46. sb.replace(textBeginFishing, textEndFishing, toChangeFishing);
  47.  
  48. int textBeginCooking = sb.indexOf("character-skill = 10");
  49. int textEndCooking = sb.indexOf("character-skill = 11");
  50. String toChangeCooking = "character-skill = 10 1 0"+newLine;
  51.  
  52. sb.replace(textBeginCooking, textEndCooking, toChangeCooking);
  53.  
  54. fs.close();
  55. in.close();
  56. br.close();
  57.  
  58. } catch (FileNotFoundException e) {
  59. e.printStackTrace();
  60. } catch (IOException e) {
  61. e.printStackTrace();
  62. }
  63.  
  64. try {
  65. FileWriter fstream = new FileWriter(f);
  66. BufferedWriter outobj = new BufferedWriter(fstream);
  67. outobj.write(sb.toString());
  68. outobj.close();
  69. } catch (Exception e) {
  70. System.err.println("Error: " + e.getMessage());
  71. }
  72. }
  73.  
  74. }
  75.  
  76.  
  77. public static void main(String[] args) {
  78. new Main();
  79. }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement