Last active
September 10, 2015 11:10
-
-
Save ableasdale/f758610aa47f5b06f18e to your computer and use it in GitHub Desktop.
URLEncode multiple lines in a text file (for use with JMeter)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedReader; | |
import java.io.BufferedWriter; | |
import java.io.IOException; | |
import java.net.URLEncoder; | |
import java.nio.charset.Charset; | |
import java.nio.file.Files; | |
import java.nio.file.Path; | |
import java.nio.file.Paths; | |
import java.nio.file.StandardOpenOption; | |
/** | |
* Created with IntelliJ IDEA. | |
* User: Alex | |
* Date: 10/09/15 | |
* Time: 10:36 | |
*/ | |
public class UrlEncodeTextFile { | |
public static void main(String[] args) { | |
String folderPath = "D:\\data"; | |
Path source = Paths.get(folderPath, "source.txt"); | |
Path dest = Paths.get(folderPath, "dest.txt"); | |
Charset charset = Charset.forName("UTF-8"); | |
try { | |
BufferedWriter writer = Files.newBufferedWriter(dest, charset, StandardOpenOption.CREATE); | |
BufferedReader reader = Files.newBufferedReader(source, charset); | |
String line = null; | |
while ((line = reader.readLine()) != null) { | |
String ul = URLEncoder.encode(line, "UTF-8") + "\n"; | |
writer.write(ul, 0, ul.length()); | |
} | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment