Advertisement
Tezlaz

fw

Aug 6th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. package scripts.tools;
  2.  
  3. import java.io.BufferedWriter;
  4. import java.io.File;
  5. import java.io.FileOutputStream;
  6. import java.io.FileReader;
  7. import java.io.IOException;
  8. import java.io.LineNumberReader;
  9. import java.io.OutputStreamWriter;
  10. import java.io.Writer;
  11. import java.util.ArrayList;
  12. import java.util.List;
  13.  
  14. public class FileWriting {
  15.  
  16. public static String content;
  17. public static String itemName;
  18. private static final String newLine = System.getProperty("line.separator");
  19. public static List<Long> priceListArray = new ArrayList<Long>();
  20.  
  21. public static long lowerPercentile;
  22. public static long upperPercentile;
  23.  
  24. public void writing() {
  25. try {
  26. //Change the file location to whatever suits your OS
  27. File fileLocation = new File("C:/Users/userr/Desktop/TriBot/miningTimeTaken.txt");
  28. FileOutputStream fos = new FileOutputStream(fileLocation, true);
  29. OutputStreamWriter osw = new OutputStreamWriter(fos);
  30. Writer w = new BufferedWriter(osw);
  31. if (!fileLocation.exists()) {
  32. fileLocation.createNewFile();
  33. System.out.println(itemName + " has not been analised. " + itemName + ".txt Sucessfully created...");
  34. }
  35. w.write(newLine + content);
  36. System.out.println("Data written to: " + itemName +".txt");
  37. w.close();
  38. } catch (IOException e) {
  39. System.err.println("There was an error writing to the file " + itemName + ".txt");
  40. }
  41. }
  42.  
  43. public static void WriteFile(String toWrite) {
  44. content = toWrite;
  45. FileWriting write = new FileWriting();
  46. write.writing();
  47. }
  48.  
  49. public static int LineNumber() throws IOException {
  50. LineNumberReader lnr = new LineNumberReader(new FileReader(new File("C:/Users/Josh/Desktop/Parabot/JMerch/PriceData/" + itemName + ".txt")));
  51. lnr.skip(Long.MAX_VALUE);
  52. lnr.close();
  53. return lnr.getLineNumber() + 1; //Add 1 because line index starts at 0
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement