Skip to content

Instantly share code, notes, and snippets.

@h1ddengames
Last active July 13, 2020 04:29
Show Gist options
  • Save h1ddengames/4c82ffee1f3ed32d5fd3783e320c3a2e to your computer and use it in GitHub Desktop.
Save h1ddengames/4c82ffee1f3ed32d5fd3783e320c3a2e to your computer and use it in GitHub Desktop.
import java.io.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Tools {
public void combineFiles(File fileInput, File fileOutput) throws IOException {
BufferedWriter writer = new BufferedWriter(new FileWriter(fileOutput));
BufferedReader reader = new BufferedReader(new FileReader(fileInput));
String line;
while ((line = reader.readLine()) != null) {
writer.write(line + "\n");
}
writer.close();
reader.close();
}
public int findNumberFromString(String str) {
Pattern p = Pattern.compile("\\d+"); // Defines a pattern to search a string for only numbers.
Matcher m = p.matcher(str); // Find the numbers in a given string using the searching pattern.
if(m.find()) {
return Integer.parseInt(m.group());
}
return Integer.MIN_VALUE;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment