Java Examples for java.io.FileWriter
The following java examples will help you to understand the usage of java.io.FileWriter. These source code samples are taken from different open source projects.
Example 1
| Project: audit-master File: MainActivity.java View source code |
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
String dirPath = "/sdcard0/test/";
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
File file = new File(dirPath + "bufferWritter");
FileWriter fileWritter = new FileWriter(file, true);
BufferedWriter bufferWritter = new BufferedWriter(fileWritter);
bufferWritter.write("this is a test");
bufferWritter.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}Example 2
| Project: maven-surefire-master File: FileHelper.java View source code |
public static void writeFile(String fileName, String content) {
try {
File target = new File(System.getProperty("user.dir"), "target").getCanonicalFile();
File listenerOutput = new File(target, fileName);
FileWriter out = new FileWriter(listenerOutput, true);
out.write(content);
out.flush();
out.close();
} catch (IOException exception) {
throw new RuntimeException(exception);
}
}Example 3
| Project: surefire-master File: FileHelper.java View source code |
public static void writeFile(String fileName, String content) {
try {
File target = new File(System.getProperty("user.dir"), "target").getCanonicalFile();
File listenerOutput = new File(target, fileName);
FileWriter out = new FileWriter(listenerOutput, true);
out.write(content);
out.flush();
out.close();
} catch (IOException exception) {
throw new RuntimeException(exception);
}
}Example 4
| Project: Aspose_Pdf_Java-master File: ExtractTextFromAnParticularPageRegion.java View source code |
public static void main(String[] args) throws IOException {
// open document
Document doc = new Document("page_0001.pdf");
// create TextAbsorber object to extract text
TextAbsorber absorber = new TextAbsorber();
absorber.getTextSearchOptions().setLimitToPageBounds(true);
absorber.getTextSearchOptions().setRectangle(new Rectangle(100, 200, 250, 350));
// accept the absorber for first page
doc.getPages().get_Item(1).accept(absorber);
// get the extracted text
String extractedText = absorber.getText();
// create a writer and open the file
BufferedWriter writer = new BufferedWriter(new FileWriter(new java.io.File("ExtractedText.txt")));
// write extracted contents
writer.write(extractedText);
// Close writer
writer.close();
}Example 5
| Project: dbo-2015-master File: Gravar4.java View source code |
public static void main(String[] args) throws Exception {
// banco.csv
File alunos = new File("alunos.csv");
// Comma Separated Values
// Valores Separados por VÃrgula
// Ex.:
// 11030226;Ana Flávia;Moraes;02/07/1999
FileWriter writer = new FileWriter(alunos, true);
Aluno a = new Aluno();
a.setMatricula(11030226);
a.setNome("Ana Flávia");
a.setSobrenome("Moraes");
a.setDataNascimento(new Date("07/02/1999"));
writer.append(a.toCSV() + "\n");
Aluno a2 = new Aluno();
a2.setMatricula(11030216);
a2.setNome("Sarah Janaina");
a2.setSobrenome("Black");
a2.setDataNascimento("25/03/1999");
writer.append(a2.toCSV() + "\n");
writer.flush();
writer.close();
System.out.println("0k");
}Example 6
| Project: featurehouse_fstcomp_examples-master File: Connection.java View source code |
protected static void log(String filename, String content) {
File datei = new File(filename + "_log.txt");
try {
FileWriter schreiber = new FileWriter(datei, true);
BufferedWriter bw = new BufferedWriter(schreiber);
bw.write(content);
bw.newLine();
bw.close();
} catch (Exception e) {
System.out.println("File not found!");
}
}Example 7
| Project: gluster-ovirt-poc-master File: XmlDocumentTest.java View source code |
@Test
public void Load() throws IOException {
final java.io.File temp = java.io.File.createTempFile("test-", ".xml");
try {
FileWriter writer = new FileWriter(temp);
writer.write("<?xml version=\"1.0\"?>\n <foo> <bar/> <!-- comment --> </foo>");
writer.close();
final XmlDocument document = new XmlDocument();
for (int i = 0; i < 2048; i++) {
document.Load(temp.getAbsolutePath());
}
} finally {
temp.delete();
}
}Example 8
| Project: GOOL-master File: RecognizerMatcherTest.java View source code |
/**
* @param args
*/
public static void main(String[] args) {
RecognizerMatcher.init("java");
RecognizerMatcher.matchImport("java.io.File");
RecognizerMatcher.printMatchTables();
System.out.println(RecognizerMatcher.matchClass("java.io.File"));
System.out.println(RecognizerMatcher.matchClass("java.io.FileReader"));
System.out.println(RecognizerMatcher.matchClass("java.io.FileWriter"));
System.out.println(RecognizerMatcher.matchClass("java.io.BufferedReader"));
System.out.println(RecognizerMatcher.matchClass("java.io.BufferedWriter"));
System.out.println(RecognizerMatcher.matchMethod("java.io.File.createNewFile():boolean"));
}Example 9
| Project: Leboncoin-master File: Utils.java View source code |
public static void debug(String content) {
try {
File file = new File("debug.twt");
// if file doesnt exists, then create it
if (!file.exists()) {
file.createNewFile();
}
FileWriter fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
bw.write(content);
bw.close();
} catch (Exception e) {
e.printStackTrace();
}
}Example 10
| Project: preservation-tools-master File: XmlOutput.java View source code |
public static void createsXMLHeader() throws IOException {
// TODO: Add Folder Browser Dialog
xmlSimpleWriter = new PrintWriter(new FileWriter("C:\\Users\\Friese Yvonne\\Desktop\\ZBW LZA\\Computer Science\\XML und Style\\xmltest.xml"));
String xmlVersion = "xml version='1.0'";
String xmlEncoding = "encoding='ISO-8859-1'";
// TODO: Choose Stylesheet from folder FileBrowseDialog
String xmlStylesheet = "TiffTagStyle.xsl";
xmlSimpleWriter.println("<=?" + xmlVersion + " " + xmlEncoding + "?>");
xmlSimpleWriter.println("<?xml-stylesheet type=\"test/xsl\" href =\"" + xmlStylesheet + "\"?>");
}Example 11
| Project: open-mika-master File: jdk11.java View source code |
public void test(TestHarness testharness) {
TestHarness harness = testharness;
harness.setclass("java.io.FileWriter");
try {
FileWriter fr1 = new FileWriter("tmpfile");
harness.check(true, "FileWriter(string)");
FileWriter fr1a = new FileWriter("tmpfile", true);
harness.check(true, "FileWriter(string, boolean)");
File f2 = new File("tmpfile");
FileWriter fr2 = new FileWriter(f2);
harness.check(true, "FileWriter(File)");
FileOutputStream fis = new FileOutputStream(f2);
FileWriter fr3 = new FileWriter(fis.getFD());
harness.check(true, "FileWriter(FileDescriptor)");
} catch (IOException e) {
harness.fail("Can't open file 'choices'");
}
}Example 12
| Project: 101simplejava-master File: Unparsing.java View source code |
/**
* Method to parse a company to a jsonfile
* @param c
* @param file
*/
public static void unparseToFile(Company c, String file) {
GsonBuilder builder = new GsonBuilder();
builder.setPrettyPrinting();
Gson gson = builder.create();
FileWriter writer;
try {
writer = new FileWriter(file);
String json = gson.toJson(c);
writer.write(json);
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}Example 13
| Project: Android-Monkey-Adapter-master File: PropertiesHelper.java View source code |
public static void setProperties(String id, String section, Map<String, String> properties, boolean append) {
try {
String file = LocationHelper.getPropertiesLocation(id);
BufferedWriter bw = new BufferedWriter(new FileWriter(file, append));
bw.newLine();
bw.write(String.format("[%s]", section));
bw.newLine();
for (Map.Entry<String, String> prop : properties.entrySet()) {
bw.write(String.format("%s=%s", prop.getKey(), prop.getValue()));
bw.newLine();
}
bw.flush();
bw.close();
} catch (FileLocationException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}Example 14
| Project: batch-import-master File: PerformanceTestFile.java View source code |
public static void createTestFile() throws IOException {
final BufferedWriter writer = new BufferedWriter(new FileWriter(TEST_CSV));
for (int row = 0; row < ROWS; row++) {
for (int col = 0; col < COLS; col++) {
if (col > 0)
writer.write('\t');
writer.write("\"" + String.valueOf(row * col) + "\"");
}
writer.write('\n');
}
writer.close();
}Example 15
| Project: BridgeDb-master File: Measure.java View source code |
public void add(String key, String value, String unit) {
try {
DateFormat fmt = new SimpleDateFormat("dd MMM yy HH:mm z");
// open file for appending.
FileWriter fw = new FileWriter(dest, true);
fw.write(fmt.format(new Date()) + "\t" + key + "\t" + value + "\t" + unit + "\n");
fw.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}Example 16
| Project: Cardinal-Plus-master File: WebUtils.java View source code |
public static void readURLAndSaveToFile(URL url, File file) {
URLConnection urlConnection;
try {
urlConnection = url.openConnection();
BufferedReader reader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
String line;
if (!file.exists()) {
file.createNewFile();
}
FileWriter fileWriter = new FileWriter(file.getAbsoluteFile());
BufferedWriter writer = new BufferedWriter(fileWriter);
while ((line = reader.readLine()) != null) {
writer.write(line + "\n");
}
writer.close();
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}Example 17
| Project: CircDesigNAGUI-master File: ScaffoldShortformSplitter.java View source code |
public static void main(String[] args) throws IOException {
File dir = new File(System.getProperty("viennaFilesDir"));
File shortform = new File(System.getProperty("sfoldInput"));
Scanner in = new Scanner(shortform);
while (in.hasNextLine()) {
String[] line = in.nextLine().split("\\s+", 2);
int len = line[1].trim().length();
PrintWriter o = new PrintWriter(new FileWriter(new File(dir.toString() + "/" + line[0] + "_" + len + ".vienna")));
o.println(len);
o.println(line[1]);
o.println(".");
o.close();
}
}Example 18
| Project: CollectiveFramework-master File: PlainTextProvider.java View source code |
@Override
public boolean downloadFile(String url, String downloadPath) {
try {
String download = StringUtils.stringFromList(WebUtils.readURL(url));
FileWriter writer = new FileWriter(downloadPath);
writer.write(download);
writer.flush();
writer.close();
return true;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}Example 19
| Project: color-maze-game-master File: ErrorReport.java View source code |
public void makeFile() {
Writer out = null;
File eFile = new File("report.txt");
try {
out = new BufferedWriter(new FileWriter(eFile));
out.write(error);
out.close();
} catch (IOException ex) {
System.out.printf("ERROR: Major irony! Error creating error report!\n");
}
}Example 20
| Project: damp.ekeko.snippets-master File: FileReporter.java View source code |
public void report(String content) throws ReportException {
try {
Writer writer = null;
try {
writer = new BufferedWriter(new FileWriter(reportFile));
writer.write(content);
} finally {
if (writer != null)
writer.close();
}
} catch (IOException ioe) {
throw new ReportException(ioe);
}
}Example 21
| Project: deepnighttwo-master File: FileLine.java View source code |
public static void main(String[] args) throws IOException {
File f = new File("C:\\ttt.txt");
if (f.exists() == false || f.isFile() == false) {
f.createNewFile();
}
PrintWriter pw = new PrintWriter(new FileWriter(f));
pw.write("rn: AAA" + "\r\n" + "BBB");
pw.write("r: AAA" + "\r" + "BBB");
pw.write("n: AAA" + "\n" + "BBB");
pw.flush();
String str = (int) ('\r') + "\t" + (int) ('\n');
System.out.println(str);
pw.close();
}Example 22
| Project: DesignPatternAnalysis-master File: FileReporter.java View source code |
public void report(String content) throws ReportException {
try {
Writer writer = null;
try {
writer = new BufferedWriter(new FileWriter(reportFile));
writer.write(content);
} finally {
if (writer != null)
writer.close();
}
} catch (IOException ioe) {
throw new ReportException(ioe);
}
}Example 23
| Project: DeviveWallSuite-master File: FileUtilities.java View source code |
public static void writeJsonToOutputFile(String json, String filePath) {
FileWriter fr = null;
BufferedWriter br = null;
try {
fr = new FileWriter(new File(filePath));
br = new BufferedWriter(fr);
if (json != null) {
br.write(json);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
closeStreams(br, fr);
}
}Example 24
| Project: ecore-master File: PrintFile.java View source code |
public static void AddtoFile(String msg) {
try {
java.util.Date d = new java.util.Date();
if (file_name == "") {
file_name = "C:\\Users\\Mehdi\\Dropbox\\CloudSimDemo" + d.getTime() + ".txt";
}
File file = new File(file_name);
// if file doesnt exists, then create it
if (!file.exists()) {
file.createNewFile();
}
FileWriter fw = new FileWriter(file.getAbsoluteFile(), true);
String text = System.lineSeparator() + msg.replace("\n", System.lineSeparator());
fw.write(text);
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
}Example 25
| Project: Egg-master File: FileAccountOutput.java View source code |
@Override
public void save(AuthenticatedAccount account) throws IOException {
synchronized (file) {
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(file, true));
bufferedWriter.write(account.getUsername() + ":" + account.getCredential().toString() + System.lineSeparator());
bufferedWriter.flush();
bufferedWriter.close();
EggCrack.LOGGER.fine("Account " + account.getUsername() + " saved to file \"" + file.getAbsolutePath() + "\".");
}
}Example 26
| Project: EggCrack-master File: FileAccountOutput.java View source code |
@Override
public void save(AuthenticatedAccount account) throws IOException {
synchronized (file) {
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(file, true));
bufferedWriter.write(account.getUsername() + ":" + account.getCredential().toString() + System.lineSeparator());
bufferedWriter.flush();
bufferedWriter.close();
EggCrack.LOGGER.fine("Account " + account.getUsername() + " saved to file \"" + file.getAbsolutePath() + "\".");
}
}Example 27
| Project: egonet-master File: NameMappingWriter.java View source code |
public void writeToFile(File file) throws IOException {
FileWriter fw = new FileWriter(file);
CSVWriter csv = new CSVWriter(fw);
csv.writeNext(new String[] { "ego_name", "unused", "alter_number", "alter_name", "group" });
for (NameMapperFrame.NameMapping mapping : nameMappings) {
String name = mapping.getInterview().getIntName();
csv.writeNext(new String[] { name, "", mapping.getAlterNumber() + "", // alter name
mapping.toString(), mapping.getGroup() + "" });
}
csv.flush();
fw.close();
}Example 28
| Project: embeddedlinux-jvmdebugger-intellij-master File: Template.java View source code |
/**
* Processes a freemarker template based on some parameters
*/
public void toFile() {
Configuration configuration = new Configuration();
configuration.setClassForTemplateLoading(classContext, "/");
try {
freemarker.template.Template template = configuration.getTemplate(name);
Writer file = new FileWriter(new File(outputFile));
template.process(data, file);
file.flush();
file.close();
} catch (Exception e) {
}
}Example 29
| Project: Expense-Tracker-App-master File: FileManager.java View source code |
public static final File generateFile(FileGeneratorParser fileGeneratorParser) {
if (Environment.getExternalStorageState().equalsIgnoreCase(Environment.MEDIA_MOUNTED)) {
File root = new File(Environment.getExternalStorageDirectory(), "ExpenseTracker");
if (!root.exists()) {
root.mkdirs();
}
File gpxfile = new File(root, getFileName());
try {
FileWriter writer = new FileWriter(gpxfile);
writer.append(fileGeneratorParser.generateFileContent());
writer.flush();
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
return gpxfile;
}
return null;
}Example 30
| Project: find-sec-bugs-master File: PathTraversal.java View source code |
public static void main(String[] args) throws IOException, URISyntaxException {
String input = args.length > 0 ? args[0] : "../../../../etc/password";
new File(input);
new File("test/" + input, "misc.jpg");
new RandomAccessFile(input, "r");
new File(new URI(args[0]));
new FileReader(input);
new FileInputStream(input);
new FileWriter(input);
new FileWriter(input, true);
new FileOutputStream(input);
new FileOutputStream(input, true);
// false positive test
new RandomAccessFile("safe", args[0]);
new FileWriter("safe".toUpperCase());
new File(new URI("safe"));
}Example 31
| Project: FireflowEngine20-master File: UploadTest.java View source code |
@Test
public void test_upload() throws Throwable {
Request req = Request.create(getBaseURL() + "/upload/image", METHOD.POST);
File f = File.createTempFile("nutz", "data");
FileWriter fw = new FileWriter(f);
fw.write("abc");
fw.flush();
fw.close();
req.getParams().put("file", f);
FilePostSender sender = new FilePostSender(req);
Response resp = sender.send();
assertEquals("image&3", resp.getContent());
}Example 32
| Project: fpcms-master File: UnuseKeywordsUtilTest.java View source code |
@Test
public void test_getUnuseKeywords() throws IOException {
Set<String> unuseKeywords = UnuseKeywordsUtil.getUnuseKeywords();
assertFalse(unuseKeywords.isEmpty());
System.out.println("-------- done ----------" + unuseKeywords.size());
// System.out.println(unuseKeywords.size() + " " + unuseKeywords);
// System.out.println("\n\n\n");
// int i = 0;
// PrintWriter fileOut = new PrintWriter(new FileWriter("/tmp/unuseKeywords.txt"));
// for(String str : unuseKeywords) {
// print(str,fileOut);
// i++;
// if(i % 30 == 0) {
// System.out.println();
// fileOut.println();
// }
// }
// fileOut.close();
}Example 33
| Project: freehep-ncolor-pdf-master File: SAXTest.java View source code |
/**
* @param args
*/
public static void main(String[] args) {
if (args.length != 1) {
System.out.println("Usage: SAXTest filename.xml");
System.exit(1);
}
try {
FileInputStream fr = new FileInputStream(args[0]);
XMLHepRepReader reader = new XMLHepRepReader(fr);
HepRep hepRep = reader.next();
reader.close();
FileWriter fw = new FileWriter("SampleEvent.out.xml");
XMLHepRepWriter writer = new XMLHepRepWriter(fw);
writer.write(hepRep);
writer.close();
} catch (Exception e) {
System.out.println(e);
e.printStackTrace();
}
}Example 34
| Project: frodo-master File: DataPresenter.java View source code |
public void executeDiskIOTaskOnUiThread() {
try {
File file = File.createTempFile("test", ".txt");
FileWriter writer = new FileWriter(file);
writer.write("This is Fernando Cejas testing something");
writer.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
}
}Example 35
| Project: GoMotion-master File: FileUtil.java View source code |
public static void writeFile(String fileName, float f) {
FileWriter fileWriter = null;
PrintWriter printWriter = null;
try {
fileWriter = new FileWriter(fileName);
printWriter = new PrintWriter(fileWriter);
printWriter.println(f + "\n");
} catch (IOException e) {
Log.d(TAG, e.getMessage());
} finally {
try {
if (printWriter != null) {
printWriter.close();
}
if (fileWriter != null) {
fileWriter.close();
}
} catch (IOException e) {
Log.d(TAG, e.getMessage());
}
}
}Example 36
| Project: gtitool-master File: LatexExporter.java View source code |
/**
* Creates the suroundings of the LatexFile
*
* @param latex The contents of the latexFile
* @param file The latexFile
*/
public static void buildLatexFile(String latex, File file) {
//$NON-NLS-1$
String s = "\\documentclass[a4paper,11pt]{article}\n";
//$NON-NLS-1$
s += "\\usepackage{german}\n\\usepackage[utf8]{inputenc}\n";
//$NON-NLS-1$
s += "\\usepackage{tree-dvips}\n";
//$NON-NLS-1$
s += "\\begin{document}\n";
s += latex;
//$NON-NLS-1$
s += "\n\\end{document}";
FileWriter fw;
try {
fw = new FileWriter(file);
fw.write(s);
fw.close();
} catch (IOException exc) {
exc.printStackTrace();
}
}Example 37
| Project: HazelcastShowAndTell-master File: FileWithNumbersGenerator.java View source code |
public static void main(String[] args) throws IOException {
for (int fileNumber = 1; fileNumber <= NUMBER_OF_FILES; fileNumber++) {
PrintWriter writer = new PrintWriter(new FileWriter("random_numbers_" + fileNumber + ".txt"));
Random generator = new Random();
generateRandomNumbersToTheFile(writer, generator);
writer.close();
}
}Example 38
| Project: intellij-samples-master File: LocateDuplicates.java View source code |
public static void main(String[] args) {
String concat = "";
for (int i = 0; i < args.length; i++) {
String arg = args[i];
System.out.println(arg);
concat += arg + ", ";
}
try {
FileWriter fw = new FileWriter("temp");
fw.write(concat);
} catch (IOException e) {
e.printStackTrace();
}
}Example 39
| Project: jeql-master File: IOFunction.java View source code |
public static boolean writeTextFile(String filename, String value) {
try {
FileWriter fileWriter = new FileWriter(filename);
BufferedWriter bufWriter = new BufferedWriter(fileWriter);
bufWriter.write(value);
bufWriter.close();
} catch (IOException ex) {
System.out.println(ex.getMessage());
return false;
}
return true;
}Example 40
| Project: jsystem-master File: LocalTest2.java View source code |
/**
* Create file MyFile2.txt
*/
public void testCreateFile2() throws Exception {
File newFile;
Writer output = null;
sleep(10000);
String text = "Hello all! this is creating file by java and should be biggger than others";
newFile = new File("MyFile2.txt");
report.step("Create file 2 at : " + newFile.getAbsolutePath());
output = new BufferedWriter(new FileWriter(newFile));
output.write(text);
output.close();
}Example 41
| Project: keshmesh-master File: FileWriterFactory.java View source code |
@Override
public Writer create() {
try {
File keshmeshHome = new File(Constants.KESHMESH_HOME);
if (!keshmeshHome.exists()) {
return stringWriterFactory.create();
}
return new FileWriter(new File(Constants.KESHMESH_HOME + Constants.FILE_SEPARATOR + filename));
} catch (IOException e) {
throw new RuntimeException(e);
}
}Example 42
| Project: Link-Time-Optimizer-master File: Compare.java View source code |
public static void main(String[] args) throws IOException {
long t1 = System.nanoTime();
App.main(args);
System.out.printf("%n---%n%n");
long t2 = System.nanoTime();
AppOptimized.main(args);
System.out.printf("%n---%n%n");
long t3 = System.nanoTime();
System.out.printf("Unoptimized: %10.3f ms%nOptimized: %10.3f ms%n---%n", (t2 - t1) * .000001, (t3 - t2) * .000001);
PrintWriter f = new PrintWriter(new FileWriter("comparison.txt", true));
f.printf("%s %s%n", args[0], args[1]);
f.printf("Unoptimized: %10.3f ms%nOptimized: %10.3f ms%n---%n", (t2 - t1) * .000001, (t3 - t2) * .000001);
f.close();
}Example 43
| Project: MiA-master File: WikipediaDataConverter.java View source code |
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new FileReader("links-simple-sorted.txt"));
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("links-converted.txt")));
String line;
while ((line = in.readLine()) != null) {
Matcher m = NUMBERS.matcher(line);
m.find();
long userID = Long.parseLong(m.group());
while (m.find()) {
out.println(userID + "," + Long.parseLong(m.group()));
}
}
in.close();
out.close();
}Example 44
| Project: Mint-Athena-master File: XSDDocumentationGeneration.java View source code |
/**
* @param args
*/
public static void main(String[] args) throws Exception {
JFileChooser chooser = new JFileChooser();
if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
File selected = chooser.getSelectedFile();
String path = selected.getAbsolutePath();
XSDParser parser = new XSDParser(path);
JSONObject documentation = parser.buildDocumentation();
String output = selected.getParent() + "/documentation.json";
FileWriter writer = new FileWriter(new File(output));
writer.write(documentation.toString());
writer.flush();
writer.close();
}
}Example 45
| Project: Mint-master File: XSDDocumentationGeneration.java View source code |
/**
* @param args
*/
public static void main(String[] args) throws Exception {
JFileChooser chooser = new JFileChooser();
if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
File selected = chooser.getSelectedFile();
String path = selected.getAbsolutePath();
XSDParser parser = new XSDParser(path);
JSONObject documentation = parser.buildDocumentation();
String output = selected.getParent() + "/documentation.json";
FileWriter writer = new FileWriter(new File(output));
writer.write(documentation.toString());
writer.flush();
writer.close();
}
}Example 46
| Project: molgenis_apps-legacy-master File: DownloadExample.java View source code |
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
try {
JobDataMap job_data = context.getJobDetail().getJobDataMap();
String path = job_data.getString("__path");
FileWriter fstream = new FileWriter(path);
BufferedWriter out = new BufferedWriter(fstream);
out.write("Hello Java");
//Close the output stream
out.close();
} catch (IOException e) {
throw new JobExecutionException(e);
}
}Example 47
| Project: NatashaHellowYandex-master File: Downloader.java View source code |
public static void main(String[] args) {
try {
String urlStr = "http://ya.ru";
URL url = new URL(urlStr);
HttpURLConnection httpConnection = (HttpURLConnection) url.openConnection();
InputStream is = httpConnection.getInputStream();
String s = Utils.inputStreamToString(is);
System.out.println(s);
File file = new File("out.txt");
FileWriter fileWriter = new FileWriter(file);
fileWriter.write(s);
fileWriter.close();
} catch (IOException e) {
e.printStackTrace();
}
}Example 48
| Project: NeuroSky-master File: Playground.java View source code |
public static void main(String[] args) {
String outputFile = "C:\\Users\\smoxley\\Downloads\\network-stats.txt";
int numObservations = 5;
Random yRNG = new Random();
Double[] y = new Double[numObservations];
for (int i = 0; i < numObservations; i++) {
y[i] = yRNG.nextDouble();
}
Evolver evolver = new Evolver(y);
File output = new File(outputFile);
try {
FileWriter writer = new FileWriter(output);
writer.write(evolver.getFittestNetwork().getStats());
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}Example 49
| Project: nutz-master File: UploadTest.java View source code |
@Test
public void test_upload() throws Throwable {
Request req = Request.create(getBaseURL() + "/upload/image", METHOD.POST);
File f = File.createTempFile("nutz", "data");
FileWriter fw = new FileWriter(f);
fw.write("abc");
fw.flush();
fw.close();
req.getParams().put("file", f);
FilePostSender sender = new FilePostSender(req);
Response resp = sender.send();
assertEquals("image&3", resp.getContent());
}Example 50
| Project: nutzmole-master File: FreemarkerHelp.java View source code |
public static final void make(String path, String templateName, Map<String, Object> datas) {
try {
Files.createNewFile(new File(path));
Template template = cfg.getTemplate(templateName);
Writer out = new FileWriter(path);
template.process(datas, out);
out.flush();
out.close();
} catch (Throwable e) {
e.printStackTrace();
}
}Example 51
| Project: n_e_b_u_l_a-master File: BasicTest.java View source code |
public static void writeFile(String dir, String fileName, String content) {
try {
File f = new File(dir, fileName);
if (!f.getParentFile().exists())
f.getParentFile().mkdirs();
FileWriter w = new FileWriter(f);
BufferedWriter bw = new BufferedWriter(w);
bw.write(content);
bw.close();
w.close();
} catch (IOException ioe) {
System.err.println("can't write file");
ioe.printStackTrace(System.err);
}
}Example 52
| Project: OneSwarm-master File: DataUsageWriter.java View source code |
public void run() {
while (true) {
try {
FileWriter out = new FileWriter(storage);
out.write(writeData);
out.close();
} catch (Exception E) {
E.printStackTrace();
}
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}Example 53
| Project: PortlandStateJava-master File: WriteToFileUsingTryWithResources.java View source code |
/**
* The first argument is the file to write to.
*/
public static void main(String[] args) {
// Wrap a PrintWriter around System.err
PrintWriter err = new PrintWriter(System.err, true);
try (Writer writer = new FileWriter(args[0])) {
// Write the command line arguments to the file
for (int i = 1; i < args.length; i++) {
writer.write(args[i]);
writer.write('\n');
}
// All done
writer.flush();
} catch (IOException ex) {
err.println("** " + ex);
}
}Example 54
| Project: poseidon-rest-master File: CsvWriter.java View source code |
public void writeCsvToFile(String csv, String filename, String csvdir) {
File f = new File(csvdir + filename);
if (f.exists()) {
throw new PoseidonException(Http.Status.BAD_REQUEST, "Fakturafil med navnet " + filename + " eksisterer allerede");
}
BufferedWriter writer = null;
try {
writer = new BufferedWriter(new FileWriter(f));
writer.write(csv);
writer.flush();
} catch (IOException e) {
throw new PoseidonException(Http.Status.INTERNAL_SERVER_ERROR, e.getMessage());
} finally {
if (writer != null) {
try {
writer.close();
} catch (IOException e) {
throw new PoseidonException(Http.Status.INTERNAL_SERVER_ERROR, e.getMessage());
}
}
}
}Example 55
| Project: REST-OCD-Services-master File: GraphMlGraphOutputAdapterTest.java View source code |
@Test
public void test() throws AdapterException, IOException {
CustomGraph graph = OcdTestGraphFactory.getSawmillGraph();
graph.setEdgeWeight(graph.getEdgeArray()[0], 2);
GraphOutputAdapter adapter = new GraphMlGraphOutputAdapter();
adapter.setWriter(new FileWriter(OcdTestConstants.sawmillGraphMlOutputPath));
adapter.writeGraph(graph);
}Example 56
| Project: s-tea-master File: AddToFileWrite.java View source code |
public static void writeContext(String text, String fname) {
if (!new File(fname).exists()) {
MyFile.createFile(fname);
}
try {
fw = new FileWriter(fname, true);
fw.write(text);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (fw != null) {
fw.close();
fw = null;
}
} catch (IOException e) {
e.printStackTrace();
}
}
}Example 57
| Project: S1-Go-master File: BlockWriter.java View source code |
String write(String blockTime, String log) {
File dir = new File(getPath());
if (!dir.exists()) {
dir.mkdirs();
}
File file = new File(dir, blockTime + ".log");
FileWriter writer = null;
try {
writer = new FileWriter(file);
writer.write(log);
writer.flush();
} catch (IOException var15) {
var15.printStackTrace();
} finally {
if (writer != null) {
try {
writer.close();
} catch (IOException var14) {
var14.printStackTrace();
}
}
}
return file.getAbsolutePath();
}Example 58
| Project: TagRec-master File: UserTagDistribution.java View source code |
public static void calculate(BookmarkReader reader, String dataset) {
List<Integer> userSizes = new ArrayList<Integer>();
List<List<Bookmark>> userBookmarks = Utilities.getBookmarks(reader.getBookmarks(), false);
for (List<Bookmark> userB : userBookmarks) {
userSizes.add(userB.size());
}
Collections.sort(userSizes, Collections.reverseOrder());
try {
FileWriter userWriter = new FileWriter(new File("./data/csv/" + dataset + "_userDist.txt"));
BufferedWriter userBW = new BufferedWriter(userWriter);
for (int size : userSizes) {
userBW.write(size + "\n");
}
userBW.close();
} catch (Exception e) {
e.printStackTrace();
}
}Example 59
| Project: vitry-master File: writeFile.java View source code |
public Object apply(Object name, Object contents) {
try {
String name2 = ((String) name).replaceFirst("~", System.getProperty("user.home"));
Writer w = new FileWriter(name2);
w.write((String) contents);
w.close();
} catch (IOException e) {
if (Build.DEBUG) {
e.printStackTrace();
} else {
throw new IOError("Could not write file " + name);
}
}
return VitryRuntime.NIL;
}Example 60
| Project: vorburgers-blueprints-master File: ClassFilesGenerator.java View source code |
public static void generate(File rootDir, Class<?> klass) throws IOException {
if (!rootDir.exists())
throw new IllegalArgumentException(rootDir + " doesn't exist");
File srcDir = new File(rootDir, ClassInterfaceGenerator.packageInDottedForm(klass).replace('.', '/'));
srcDir.mkdirs();
File javaSourceFile = new File(srcDir, klass.name() + ".java");
Writer writer = new FileWriter(javaSourceFile);
ClassInterfaceGenerator.generate(klass, writer, true);
writer.close();
}Example 61
| Project: WebGatherer---Scraper-and-Analyzer-master File: PersistenceImpl_WriteToFile.java View source code |
public void writeToFile(String filePath, String text) {
try {
// Create file
FileWriter fstream = new FileWriter(filePath);
BufferedWriter out = new BufferedWriter(fstream);
out.write(text);
out.close();
} catch (//Catch exception if any
Exception //Catch exception if any
e) {
System.err.println("Error: " + e.getMessage());
}
}Example 62
| Project: zt-zip-master File: ReplaceEntryExample.java View source code |
public static void replaceEntry() throws Exception {
// lets unpack a file
File zipArchive = new File("src/test/resources/demo.zip");
File resultingFile = new File("foo.txt");
ZipUtil.unpackEntry(zipArchive, "foo.txt", resultingFile);
// lets work with the file a bit
FileWriter fw = new FileWriter(resultingFile);
fw.write("Hello World!\n");
fw.close();
ZipUtil.replaceEntry(zipArchive, "foo.txt", resultingFile);
}Example 63
| Project: android_libcore-master File: FileWriterTest.java View source code |
/**
* @tests java.io.FileWriter#FileWriter(java.io.File)
*/
@TestTargetNew(level = TestLevel.PARTIAL_COMPLETE, method = "FileWriter", args = { java.io.File.class })
public void test_ConstructorLjava_io_File() {
// Test for method java.io.FileWriter(java.io.File)
try {
fos = new FileOutputStream(f.getPath());
fos.write("Test String".getBytes());
fos.close();
bw = new BufferedWriter(new FileWriter(f));
bw.write(" After test string", 0, 18);
bw.close();
br = new BufferedReader(new FileReader(f.getPath()));
char[] buf = new char[100];
int r = br.read(buf);
br.close();
assertEquals("Failed to write correct chars", " After test string", new String(buf, 0, r));
} catch (Exception e) {
fail("Exception during Constructor test " + e.toString());
}
}Example 64
| Project: millipede-master File: LargFile.java View source code |
public static void writeFile(String path, int size, int bs) throws IOException {
long len = 1024L * 1024L * 1024L * size;
long sz = 0;
File log = new File(path + ".log");
File f = new File(path);
java.io.FileWriter writer = new FileWriter(log);
FileOutputStream str = new FileOutputStream(f, true);
Random rnd = new Random();
byte[] b = new byte[bs];
System.out.println("1:" + len);
long time = System.currentTimeMillis();
int writes = 0;
int interval = (32768 * 10000) / bs;
while (sz < len) {
rnd.nextBytes(b);
ByteBuffer buf = ByteBuffer.wrap(b);
str.getChannel().write(buf);
sz = sz + b.length;
if (writes > interval) {
float mb = (float) (writes * bs) / (1024 * 1024);
float duration = (float) (System.currentTimeMillis() - time) / 1000;
float mbps = mb / duration;
System.out.println(mbps + " (mb/s)");
writer.write(Float.toString(mbps) + "\n");
time = System.currentTimeMillis();
writes = 0;
} else {
writes++;
}
}
writer.flush();
writer.close();
}Example 65
| Project: ADSB-Sniffer-master File: Application.java View source code |
@Override
public void uncaughtException(Thread thread, Throwable throwable) {
String format = String.format("ADSBSniffer_Crashlog_%s.txt", new Date().toString());
File file = new File(Environment.getExternalStorageDirectory(), format);
try {
FileWriter fileWriter = new FileWriter(file);
fileWriter.write(String.format("Thread:\n%s\n\n", thread.toString()));
fileWriter.write(String.format("Throwable:\n%s\n\n", throwable.toString()));
fileWriter.write(String.format("Stacktrace:\n"));
throwable.printStackTrace(new PrintWriter(fileWriter));
fileWriter.flush();
fileWriter.close();
} catch (IOException e) {
e.printStackTrace();
}
originalUncaughtExceptionHandler.uncaughtException(thread, throwable);
}Example 66
| Project: AmazeFileManager-master File: Logger.java View source code |
@Override
public void run() {
FileWriter output = null;
try {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
if (s != null)
s.printStackTrace(pw);
output = new FileWriter(f.getPath());
BufferedWriter writer = new BufferedWriter(output);
writer.write(s1 + "\n");
writer.write(sw.toString());
writer.close();
output.close();
} catch (IOException e) {
}
}Example 67
| Project: Android-Tips-master File: BadUrlsSaver.java View source code |
/**
* ä¿?å˜æœ‰é—®é¢˜çš„网å?€åˆ°repo目录下
*
* @param map
* @param isSaveAlLMatterUrls
* @throws IOException
*/
public static void save(Map<String, String> map, boolean isSaveAlLMatterUrls) throws IOException {
File file = new File("..\\badUrls.txt");
if (file.exists()) {
System.out.println("åˆ é™¤å…ˆå‰?文件: " + (file.delete() ? "æˆ?功" : "失败"));
}
FileWriter writer = new FileWriter(file);
BufferedWriter bufferedWriter = new BufferedWriter(writer);
for (Map.Entry<String, String> entry : map.entrySet()) {
if (isSaveAlLMatterUrls) {
bufferedWriter.write(entry.getValue() + "\t\t" + entry.getKey() + "\r\n");
} else {
if (entry.getValue().equals("TIMEOUT")) {
bufferedWriter.write(entry.getValue() + "\t\t" + entry.getKey() + "\r\n");
}
}
}
bufferedWriter.close();
}Example 68
| Project: androidperformance-master File: SDCardFileReader.java View source code |
public static void saveData(String fileName, String data) {
File sdcard = Environment.getExternalStorageDirectory();
//Get the text file
File file = new File(sdcard, fileName);
try {
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
writer.write(data);
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}Example 69
| Project: AntennaPod-master File: CrashReportWriter.java View source code |
@Override
public void uncaughtException(Thread thread, Throwable ex) {
File path = getFile();
PrintWriter out = null;
try {
out = new PrintWriter(new FileWriter(path));
out.println("[ Environment ]");
out.println("Android version: " + Build.VERSION.RELEASE);
out.println("OS version: " + System.getProperty("os.version"));
out.println("AntennaPod version: " + BuildConfig.VERSION_NAME);
out.println("Model: " + Build.MODEL);
out.println("Device: " + Build.DEVICE);
out.println("Product: " + Build.PRODUCT);
out.println();
out.println("[ StackTrace ]");
ex.printStackTrace(out);
} catch (IOException e) {
Log.e(TAG, Log.getStackTraceString(e));
} finally {
IOUtils.closeQuietly(out);
}
defaultHandler.uncaughtException(thread, ex);
}Example 70
| Project: appJavou-master File: ParticipantSendTask.java View source code |
@Override
protected Boolean doInBackground(Void... params) {
CSVWriter writer;
boolean isAttend = false;
try {
writer = new CSVWriter(new FileWriter(Constant.PATH_FILE_JAVOU));
List<String[]> data = new ArrayList<>();
data.add(Constant.FILE_COLS);
for (Participant participant : mParticipant) {
if (participant.isAttend()) {
isAttend = true;
String sex = (participant.isSex() ? "F" : "M");
data.add(new String[] { String.valueOf(participant.getCode()), participant.getName(), participant.getEmail(), participant.getPhone(), sex, participant.getCompany() });
}
}
writer.writeAll(data);
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
return isAttend;
}Example 71
| Project: ApprovalTests.Java-master File: FileUtilsTest.java View source code |
/***********************************************************************/
public void testCopyFile() throws Exception {
File first = File.createTempFile("unitTest", ".txt");
File second = File.createTempFile("unitTestCopy", ".txt");
first.deleteOnExit();
second.deleteOnExit();
FileWriter writer = new FileWriter(first);
writer.write("Mary had a little lamb");
writer.close();
FileUtils.copyFile(first, second);
assertEquals("File sizes ", first.length(), second.length());
}Example 72
| Project: aq2o-master File: CSVFileFillExporter.java View source code |
public void export(String targetFolder, List<OrderFillEvent> fills) {
try {
BufferedWriter bw = new BufferedWriter(new FileWriter(targetFolder + File.separator + "report.csv"));
bw.write("'InstId';'RefOrderID';'Side';'creationTimeInMilliseconds';'HUMAN readable';'FillAmount';'FillPrice';'LeftQuantity';");
bw.newLine();
for (OrderFillEvent ofe : fills) {
bw.write(ofe.getOptionalInstId());
bw.write(";");
bw.write(ofe.getRefOrderId());
bw.write(";");
bw.write(ofe.getSide().name());
bw.write(";");
bw.write(dcf.format(ofe.getTimeStamp().getMilliseconds()));
bw.write(";");
bw.write("" + ofe.getTimeStamp().getCalendar().getTime());
bw.write(";");
bw.write(dcf.format(ofe.getFillAmount()));
bw.write(";");
bw.write(dcf.format(ofe.getFillPrice()));
bw.write(";");
bw.write(dcf.format(ofe.getLeftQuantity()));
bw.write(";");
bw.newLine();
}
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
}Example 73
| Project: Archimulator-master File: CSVHelper.java View source code |
/**
* To CSV.
*
* @param outputCSVFileName the output CSV file name
* @param results the list of results
* @param fields the list of fields
* @param <ResultT> the result type
*/
public static <ResultT> void toCsv(String outputCSVFileName, List<ResultT> results, List<CSVField<ResultT>> fields) {
File resultDirFile = new File(outputCSVFileName).getParentFile();
if (!resultDirFile.exists()) {
if (!resultDirFile.mkdirs()) {
throw new RuntimeException();
}
}
CSVFormat format = CSVFormat.RFC4180.withHeader().withDelimiter(',').withQuoteMode(QuoteMode.ALL).withQuote('"');
try {
FileWriter writer = new FileWriter(outputCSVFileName);
CSVPrinter printer = new CSVPrinter(writer, format);
printer.printRecord(fields);
for (ResultT result : results) {
List<String> record = new ArrayList<>();
for (CSVField<ResultT> field : fields) {
record.add(field.getFunc().apply(result));
}
printer.printRecord(record);
}
printer.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}Example 74
| Project: Assignments-master File: OPDept.java View source code |
public void placeCommand(Order ord) {
customer.setName(Gui.getUsername());
prod = ord.getProduct();
quantity = ord.getQuantity();
wh.updateQuantity(prod.getName(), -quantity);
try {
FileWriter fw = new FileWriter(file, true);
fw.write(customer.getName() + " ");
fw.write(prod.getName() + " ");
fw.write(quantity + "\n");
fw.close();
} catch (IOException e) {
System.err.println(e);
}
}Example 75
| Project: atom-nuke-master File: StateManager.java View source code |
public void writeState(String nextLocation) {
if (stateFile != null) {
try {
final FileWriter fout = new FileWriter(stateFile);
fout.append(nextLocation);
fout.append("\n");
fout.close();
} catch (IOException ioe) {
LOG.error("Failed to write statefile \"" + stateFile.getAbsolutePath() + "\" - Reason: " + ioe.getMessage());
}
}
}Example 76
| Project: audit4j-core-master File: URLConfigurationIntTest.java View source code |
@Before
public void before() {
configFileLocation = System.getProperty("user.home") + "/audit4j.conf.yml";
System.out.println(configFileLocation);
YamlWriter writer;
try {
writer = new YamlWriter(new FileWriter(configFileLocation));
writer.getConfig().setClassTag("Configuration", Configuration.class);
writer.write(Configuration.DEFAULT);
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}Example 77
| Project: BACKUP_FROM_SVN-master File: TableWriter.java View source code |
private void writeColumns(FileWriter fileWriter, Table table, Database database) throws IOException {
List<List<String>> cells = new ArrayList<List<String>>();
for (Column column : table.getColumns()) {
cells.add(Arrays.asList(TypeConverterFactory.getInstance().findTypeConverter(database).convertToDatabaseTypeString(column, database), "<A HREF=\"../columns/" + table.getName().toLowerCase() + "." + column.getName().toLowerCase() + ".html" + "\">" + column.getName() + "</A>"));
//todo: add foreign key info to columns?
}
writeTable("Current Columns", cells, fileWriter);
}Example 78
| Project: beanfabrics-master File: FileLog.java View source code |
public void log(String message) {
try {
Writer writer = new FileWriter(file, true);
writer.write(messagePrefix);
writer.write(" ");
writer.write(message);
writer.write("\n");
writer.close();
} catch (IOException e) {
throw new UndeclaredThrowableException(e);
}
}Example 79
| Project: beast2-master File: XMLTest.java View source code |
@Test
public void testAnnotatedConstructor2() throws Exception {
List<Taxon> taxa = new ArrayList<>();
taxa.add(new Taxon("first one"));
taxa.add(new Taxon("second one"));
AnnotatedRunnableTestClass t = new AnnotatedRunnableTestClass(3, taxa);
XMLProducer producer = new XMLProducer();
String xml = producer.toXML(t);
assertEquals(3, (int) t.getParam1());
FileWriter outfile = new FileWriter(new File("/tmp/XMLTest.xml"));
outfile.write(xml);
outfile.close();
XMLParser parser = new XMLParser();
BEASTInterface b = parser.parseFile(new File("/tmp/XMLTest.xml"));
assertEquals(3, (int) ((AnnotatedRunnableTestClass) b).getParam1());
assertEquals(2, ((AnnotatedRunnableTestClass) b).getTaxon().size());
}Example 80
| Project: BeautifulWidgets_SkinMixer_Android-master File: SkinDataWriter.java View source code |
private void writeText(String textToWrite) {
File textFile = new File(mOutputPath);
MLog.v("copy textfile : " + textFile.toString());
BufferedWriter buffer;
try {
buffer = new BufferedWriter(new FileWriter(textFile, true));
buffer.append(textToWrite);
buffer.newLine();
buffer.close();
} catch (IOException e) {
MLog.d("Cannot write skin text: " + e.getMessage());
}
}Example 81
| Project: Beehive-master File: AbstractConfig.java View source code |
public boolean save(String file) {
try {
Yaml yaml = new Yaml();
FileWriter writer = new FileWriter(new File(file));
yaml.dump(data, writer);
writer.close();
} catch (IOException e) {
Log.error("Not able to write file " + file, e);
return false;
}
return true;
}Example 82
| Project: biobank-master File: ExceptionUtils.java View source code |
/**
* Writes fatal errors to a log file on the system's current directory.
*
* @param t
*/
public static void writeMsgToTmpFile(String fileprefix, Throwable t) {
FileWriter writer = null;
try {
//$NON-NLS-1$
File f = new File(fileprefix + System.currentTimeMillis() + ".log");
writer = new FileWriter(f);
writer.write(getErrorAndStack(t));
writer.flush();
} catch (Exception e) {
} finally {
try {
writer.close();
} catch (Exception e1) {
}
}
}Example 83
| Project: Bringers-of-Singularity-master File: ukWacToTxt.java View source code |
public static void main(String[] args) {
try {
BufferedReader br = new BufferedReader(new FileReader(args[0]));
BufferedWriter bw = new BufferedWriter(new FileWriter("corpus.txt"));
String temp;
StringBuffer sb = new StringBuffer();
while ((temp = br.readLine()) != null) {
if (temp.startsWith("<s>")) {
sb = new StringBuffer();
} else if (temp.startsWith("</s>")) {
bw.write(sb.toString().toLowerCase().trim());
bw.newLine();
} else {
String[] text = temp.split("\\t");
//ignoring the rest which is tags...
sb.append(text[0]);
sb.append(" ");
}
}
br.close();
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
}Example 84
| Project: builderator-master File: RendererTest.java View source code |
@Test
public void test() throws IOException {
MetadataExtractor generator = new MetadataExtractor(NormalJavaBean.class);
String source = new Renderer().render(generator.getMetadata());
File root = File.createTempFile("java", null);
root.delete();
root.mkdirs();
String packageDirs = NormalJavaBean.class.getPackage().getName().replace(".", System.getProperty("file.separator"));
File packageFolder = new File(root, packageDirs);
packageFolder.mkdirs();
File sourceFile = new File(packageFolder, NormalJavaBean.class.getName().replace(".", System.getProperty("file.separator")) + "Builder.java");
sourceFile.getParentFile().mkdirs();
FileWriter fileWriter = null;
try {
fileWriter = new FileWriter(sourceFile);
fileWriter.append(source);
} finally {
if (fileWriter != null) {
fileWriter.close();
}
}
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
int result = compiler.run(null, System.out, System.err, sourceFile.getPath());
Assert.assertEquals(COMPILER_SUCCESS_CODE, result);
}Example 85
| Project: Car-Cast-master File: TraceUtil.java View source code |
public static void saveTrace(Throwable e) {
Log.e(TraceUtil.class.getName(), "Huh", e);
return;
/* try {
final Writer result = new StringWriter();
long traceTime = System.currentTimeMillis();
e.printStackTrace(new PrintWriter(result));
String filename = TraceData.APP_VERSION + "-" + traceTime;
BufferedWriter bos = new BufferedWriter(new FileWriter(TraceData.FILES_PATH + "/" + filename + ".stacktrace"));
bos.write(Long.toString(traceTime));
bos.write('\n');
bos.write(result.toString());
bos.close();
} catch (Exception ebos) {
Log.e(TraceUtil.class.getName(), "Unable to save trace.", ebos);
}
*/
}Example 86
| Project: cargotracker-ddd-master File: LineParseExceptionListener.java View source code |
@Override
public void onSkipReadItem(Exception e) throws Exception {
File failedDirectory = new File(jobContext.getProperties().getProperty(FAILED_DIRECTORY));
if (!failedDirectory.exists()) {
failedDirectory.mkdirs();
}
EventLineParseException parseException = (EventLineParseException) e;
logger.log(Level.WARNING, "Problem parsing event file line", parseException);
try (PrintWriter failed = new PrintWriter(new BufferedWriter(new FileWriter(new File(failedDirectory, "failed_" + jobContext.getJobName() + "_" + jobContext.getInstanceId() + ".csv"), true)))) {
failed.println(parseException.getLine());
}
}Example 87
| Project: cargotracker-master File: LineParseExceptionListener.java View source code |
@Override
public void onSkipReadItem(Exception e) throws Exception {
File failedDirectory = new File(jobContext.getProperties().getProperty(FAILED_DIRECTORY));
if (!failedDirectory.exists()) {
failedDirectory.mkdirs();
}
EventLineParseException parseException = (EventLineParseException) e;
logger.log(Level.WARNING, "Problem parsing event file line", parseException);
try (PrintWriter failed = new PrintWriter(new BufferedWriter(new FileWriter(new File(failedDirectory, "failed_" + jobContext.getJobName() + "_" + jobContext.getInstanceId() + ".csv"), true)))) {
failed.println(parseException.getLine());
}
}Example 88
| Project: cdt-master File: ProjectConverter21.java View source code |
@Override
public IBuildObject convert(IBuildObject buildObj, String fromId, String toId, boolean isConfirmed) {
//$NON-NLS-1$
String tmpDir = System.getProperty("java.io.tmpdir");
//$NON-NLS-1$
File outputFile = new File(tmpDir + "/converterOutput21.txt");
try {
FileWriter out = new FileWriter(outputFile);
//$NON-NLS-1$
out.write("Converter for CDT 2.1 Project is invoked");
out.close();
} catch (IOException e) {
System.out.println("Exception raised.");
}
return buildObj;
}Example 89
| Project: cdt-tests-runner-master File: ProjectConverter21.java View source code |
public IBuildObject convert(IBuildObject buildObj, String fromId, String toId, boolean isConfirmed) {
//$NON-NLS-1$
String tmpDir = System.getProperty("java.io.tmpdir");
//$NON-NLS-1$
File outputFile = new File(tmpDir + "/converterOutput21.txt");
try {
FileWriter out = new FileWriter(outputFile);
//$NON-NLS-1$
out.write("Converter for CDT 2.1 Project is invoked");
out.close();
} catch (IOException e) {
System.out.println("Exception raised.");
}
return buildObj;
}Example 90
| Project: CloudSim-master File: CostumeCSVWriter.java View source code |
public void writeTofile(String[] entries) throws IOException {
// feed in your array (or convert your data to an array)
try {
writer = new CSVWriter(new FileWriter(fileAddress, true), ',', CSVWriter.NO_QUOTE_CHARACTER);
} catch (IOException e) {
Log.printConcatLine("Couldn't find the file to write to: ", fileAddress);
}
writer.writeNext(entries);
writer.flush();
writer.close();
}Example 91
| Project: codehaus-mojo-master File: AbstractScriptFactory.java View source code |
public void emit() throws Exception {
String script = getScript();
File scriptFile = new File(outputDir, getScriptName());
FileWriter out = new FileWriter(scriptFile);
try {
out.write(script);
} finally {
if (out != null) {
out.close();
}
}
scriptFile.setExecutable(true);
}Example 92
| Project: CodingSpectator-master File: FileUtilities.java View source code |
public static void append(File target, File source) throws IOException {
FileWriter targetWriter = new FileWriter(target, true);
FileReader sourceReader = new FileReader(source);
BufferedWriter out = new BufferedWriter(targetWriter);
BufferedReader in = new BufferedReader(sourceReader);
//Skip the first line (<xml version>)
String line = in.readLine();
while (line != null) {
line = in.readLine();
if (line != null) {
out.write(line);
out.newLine();
}
}
out.close();
in.close();
}Example 93
| Project: codjo-webservices-master File: ClassListGenerator.java View source code |
public void generate(File sourcesDirectory, File targetDirectory, String packageName) throws IOException {
File targetPackage = new File(sourcesDirectory, packageName.replace('.', '/'));
File resourcesDirectory = new File(targetDirectory, "resources");
if (!resourcesDirectory.exists()) {
resourcesDirectory.mkdirs();
}
File sourcesListFile = new File(resourcesDirectory, "sourcesList.txt");
BufferedWriter out = new BufferedWriter(new FileWriter(sourcesListFile, true));
File[] files = targetPackage.listFiles(new FileFilter() {
public boolean accept(File pathname) {
return pathname.getName().endsWith(".java");
}
});
for (File file : files) {
String className = file.getAbsolutePath();
className = className.substring(targetDirectory.getAbsolutePath().length() + 1, className.length() - 5);
out.write(className.replace(File.separator, "."));
out.newLine();
}
out.close();
}Example 94
| Project: consumer-dispatcher-master File: FileUtil.java View source code |
public static boolean logJobRawDataToFile(String fileName, String data) {
String filePath = "/tmp/" + fileName;
try {
FileWriter fw = new FileWriter(filePath, true);
BufferedWriter bw = new BufferedWriter(fw);
bw.write(data);
bw.close();
} catch (IOException e) {
_logger.error(e, e);
return false;
}
return true;
}Example 95
| Project: coprhd-controller-master File: XMLWriter.java View source code |
public void writeXMLToFile(String eventData, String baseName) {
try {
StringBuilder fileName = new StringBuilder(baseName);
Date now = new Date();
SimpleDateFormat format = new SimpleDateFormat("_MMMdd_HHmmsszzz");
fileName.append(format.format(now)).append(".xml");
File file = new File(fileName.toString());
FileWriter fileWriter = new FileWriter(file, true);
BufferedWriter out = new BufferedWriter(fileWriter);
out.write(eventData);
out.newLine();
out.close();
System.out.println(" -> Output file available at : " + file.getAbsolutePath());
} catch (IOException e) {
System.out.println(" --> Exception : " + e);
log.error("Caught Exception: ", e);
}
return;
}Example 96
| Project: core-integration-testing-master File: TestMojo.java View source code |
public void execute() throws MojoExecutionException, MojoFailureException {
File outFile = new File(buildDir, "out.txt");
FileWriter writer = null;
try {
outFile.getParentFile().mkdirs();
writer = new FileWriter(outFile);
writer.write("Test");
} catch (IOException e) {
throw new MojoExecutionException("Failed to write: " + outFile.getAbsolutePath(), e);
} finally {
if (writer != null) {
try {
writer.close();
} catch (IOException e) {
}
}
}
}Example 97
| Project: crawljax-master File: TestPlugin.java View source code |
@Override
public void onNewState(CrawlerContext context, StateVertex newState) {
try {
String dom = context.getBrowser().getStrippedDom();
File file = new File(hostInterface.getOutputDirectory(), context.getCurrentState().getName() + ".html");
FileWriter fw = new FileWriter(file, false);
fw.write(dom);
fw.close();
} catch (Exception e) {
e.printStackTrace();
}
}Example 98
| Project: dawn-third-master File: UploaderTestUtils.java View source code |
public static File createBogusUploadDataFile(int days) throws Exception {
File file = File.createTempFile("bogusUploadData", "csv");
FileWriter writer = new FileWriter(file);
UsageDataRecorderUtils.writeHeader(writer);
for (int index = 0; index < days * NUMBER_OF_ENTRIES_PER_DAY; index++) {
UsageDataRecorderUtils.writeEvent(writer, new UsageDataEvent("bogus", "bogus", "bogus", "bogus", "bogus", System.currentTimeMillis()));
}
writer.close();
return file;
}Example 99
| Project: Desktop-master File: ZoteroAnnoteFieldRemoverAction.java View source code |
@Override
public void performAction(File file) {
StringBuffer sb = new StringBuffer();
try {
BufferedReader br = new BufferedReader(new FileReader(file));
String line;
while ((line = br.readLine()) != null) {
if (line.trim().startsWith("annote = {")) {
while (!line.endsWith("},") && !line.endsWith("}")) {
line = br.readLine();
}
} else {
sb.append(line);
sb.append("\r\n");
}
}
br.close();
FileWriter fw = new FileWriter(file);
fw.write(sb.toString());
fw.close();
} catch (IOException e) {
DocearLogger.error(e);
}
}Example 100
| Project: DisJob-master File: ExecutorInfoTest.java View source code |
public static void main(String[] args) throws Exception {
String logInfo = "F:/debug.log";
BufferedReader reader = new BufferedReader(new FileReader(logInfo));
System.err.println(reader);
String line = "";
File file = new File("D:/result.log");
if (!file.exists()) {
file.createNewFile();
}
String key = "ff80808158867ded015886836f076b10";
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
while ((line = reader.readLine()) != null) {
if (line.indexOf(key) > 0) {
System.out.println(line);
writer.write(line);
writer.newLine();
}
}
writer.flush();
writer.close();
}Example 101
| Project: DroidconApp-master File: CacheHelper.java View source code |
public static synchronized void saveFile(Context c, String name, String data) throws IOException {
File file = locateFile(c, name);
File tempFile = new File(file.getParent(), file.getName() + ".tmp");
if (tempFile.exists())
tempFile.delete();
FileWriter out = new FileWriter(tempFile);
IOUtils.write(data, out);
out.close();
if (file.exists())
file.delete();
tempFile.renameTo(file);
}