Opening And Closing Multiple Files In While Loop

Feb 7, 2014

I'm going through a file (MySQL dump) and I wish to take the SQL and create individual files for each table (as opposed to what I do now, which is just run through the whole thing).

<code>
  BufferedReader myDumpfileReader = new BufferedReader(new FileReader(tfDumpfile.getText()));  BufferedWriter myDumpfileWriter = new BufferedWriter(new FileWriter("/users/linehanp/mydb/bin/tgac_dump/Vanilla.sql"));
while((dumpFileLine = myDumpfileReader.readLine()) != null){      DoStuff();
      MyDumfileWriter.write("Whatever");
  }
myDumpfileReader.close();myDumpfileWriter.close();
</code>

Now, this all works fine - but what I want to do is create a separate .sql file for each table.
 
However, I can't figure out the best way to do this - how do I create a new FileWriter (or instance of whatever class is required) as I'm going through the while loop? That or pointing the same one to different files as I go through the loop.
 
It can be assumed that the file may exceed RAM - I want to do it line by line rather than slurping the entire file as a string and "cheating" that way.
 
There appear to be many (a bewildering amount of) I/O options and I'm just unsure.

View Replies


ADVERTISEMENT

Opening Multiple Tabs

Sep 27, 2014

I'm now working more and more on the go and although I can carry my Macbook Air without too much trouble I've just been given an iPad Mini by work and it's far easier to do what I do with that on the move.

For work I need to open around 35 different websites at one time 4/5 times a day on the move.

With my Macbook that's no issue, as I can just use the open all function of my bookmarks, but on the iPad there is nothing that will allow me to do this.

I have looked online and a few people have had this issue and fixed it using the below Java method:

Creating a link that when clicked sets off a Javascript function that contains several window.open("url"); Clicking the link opens each website in its own tab.

View Replies View Related

Threads Stuck On Closing Brace Of While Loop

Apr 14, 2014

While analyzing the thread dumps for a performance issue in our java ee web application, I see many thread dumps stuck on a closing brace of a while loop. Here is the code block of a third party library bitronix (version 1.3.3 SNAPSHOT)
 
public XAResourceHolderState findXAResourceHolderState(XAResource xaResource) throws BitronixSystemException {
        Iterator it = resources.iterator();
        while (it.hasNext()) {
            XAResourceHolderState xaResourceHolderState = (XAResourceHolderState) it.next();
            if (xaResourceHolderState.getXAResource() == xaResource)
                return xaResourceHolderState;
        }      
        return null;
    }

The thread dumps indicate that many threads are stuck in RUNNABLE state on line number 07. What could be the possible reasons on why a thread could get stuck on a closing brace of a while loop? The iterator of the while loop is a custom implementation.

View Replies View Related

Can't Make JfileChooser Save Text File Instead Of Opening Files

Nov 13, 2014

i can't make the [JfileChooser] save text file instead of opening files.that [ComboBox] always don't show me the items that i have inserted in eclipse.

View Replies View Related

JSP :: How To Download Multiple Files Without Zipping Them

Apr 4, 2014

I need to download multiple files from my jsp,My jsp will receive a string array,and in that each array will have a filePath.I ggot the solution to download multiple files by Using ZipOutPutStream,But i don't want to Zip Them,I need to download them in a folder.In that folder i should have all the files.

<c:set var="streamValue" value="${streamValue}"/>
<%!
void addFile( ZipOutputStream outZip, File f, String name ) {
FileInputStream in = null ;
try {
// Add ZIP entry to output stream.
outZip.putNextEntry( new ZipEntry( name ) ) ;

[code].....

View Replies View Related

Can A Class Be Broken Into Multiple Source Files?

Apr 3, 2014

The problem is what to do when the source file for a class gets too big ( a judgment call for sure). Is it possible for one class to be defined in multiple files and if so how do you do it, and is it good practice?

I do see ways to refactor into a base class or move code into a helper class but sometimes the abstraction is cleaner as a single class that does a lot of stuff. My problem is how to organize a BIG class?

View Replies View Related

Downloading Multiple Files Using Java Program

Nov 24, 2014

I am downloading around 50 PDF files programmatically using Java program(like a servlet service) one after another in for loop. I am observing that , i'm getting timeout error after few files are downloaded itself. How to solve this problem and download more files programmatically using java? The files are in my server at different location.

View Replies View Related

Split Text File In Multiple Files

Jun 17, 2014

I have multiple text files that contain several docs. my files look like this:

<doc id 1> some text </doc>
<doc id 2> some more text</doc>
...

As output I want to extract the text between the tags and then write the text into several files like 1.txt, 2.txt ......

here is my code so far:

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

[Code] ....

I can not seem to get around how to print the text into several files.

View Replies View Related

JavaFX 2.0 :: Variables With Multiple FXML Files

Mar 31, 2015

I have a multi scene JavaFX FXML application [URL] ....
 
I have added a TextField to Scene2.fxml and Scene3.fxml files each scene has its own Controller Class with a ScreensController class that loads a HashMap with Id name, Node screen that is defined in the ScreensFramework

class (Main class)
public void addScreen(String name, Node screen) {screens.put(name, screen);}

So each time you click a Button on a screen (scene) you fire an ActionEvent and move to another screen

myController.setScreen(ScreensFramework.screen2ID); 

What I would like to do if it is possible is use the value in the TextField on Sceen2 and transfer it to the TextField on Scene3. I have discovered that unless both FXML files are loaded this is so far not possible. This is a desktop application. So how do you create a variable that is GLOBAL and has a life after one class is unloaded or one FXML file is unloaded?

At this point I do not want a database to accomplish this task.I have developed in Visual Basic 6 where I would just declare a global variable that could be used through out the application.

View Replies View Related

Compile Multiple Jar Files Into One From Inside Java Program?

May 17, 2014

I am trying to compile multiple jar files into one jar file from inside a java program. I know how to do this with shell scripts but I would rather have a universal application than one that will only run on Mac, Windows, or Linux. This is my current compiler code:

if(System.getProperty() == "Mac OS X"){
Runtime.getRuntime().exec("javac -classpath jar1.jar; jar2.jar");
}

I would then continue this on for Linux and Windows, but this limits my application.

View Replies View Related

Create Multiple PDF Files And Open Them At Once From Java Application

Aug 30, 2014

I am using itext to create pdf files , i have filtered some records (preferably i can say around 90) which has the option to open pdf for individual record. Now I need to open all the pdf's of filtered records on a single click , without asking for a open dialogue box. How to go about this ??

View Replies View Related

Searching For Any Entered Text In A Directory Of Multiple Scanned PDF Files

Mar 31, 2015

Within tomcat "webapps" directory, have lots of scanned PDF files (size in KB and MB).Using Java and JSP, I want to search for any user entered text in these scanned PDF files.The result must display the name of those PDF files which has that entered text.

View Replies View Related

JavaFX 2.0 :: Multiple Scene And Passing Variables With FXML Files

Mar 21, 2015

Lets say I have a desire to convert and entered value to Centigrade or Fahrenheit and that I have two Radio Buttons to designate the type of conversion with the Answer posted to a TextField on Scene Two from a button click event on Scene One ok Now I would like to convert the value in the TextField on Scene Two to Kelvin and reflect the value on Scene Three in a TextField by clicking a button on Scene Two
 
lets say  I have 4 FXML files sceneONE sceneTWO and scenMain and I created 4 controllers ControllerONE and MasterController

So far I can navigate to the different scens with just the MasterController code below...

BUT because I have two FXML files I can not capture the value in the first FXML file and pass it to the second scene
 
This project is my attempt to adapt the FXML style code from this web site

Switching to Different Screens in JavaFX and FXML | JavaFXTutorials

Which uses this code to switch scenes

    //get reference to the button's stage                stage=(Stage) btnS1.getScene().getWindow();
       //load up OTHER FXML document
       root = FXMLLoader.load(getClass().getResource("ATTwo.fxml"));

But will not permit variable transfer due to scope of variables which reside in two different FXML files
 
public class MasterController implements Initializable{@FXML public Button btnS1;
@FXML public Button btnS2;
@FXML public Label lblS1;
@FXML public Label lblS2;
@FXML public TextField txfS1;
@FXML public TextField txfS2;
@FXML public AnchorPane root;

[Code] .....

View Replies View Related

For Loop And Multiple Arrays

Dec 25, 2014

I am attempting to grab stock prices for an array of different stock tickers. In my code, I iterate through the array of stock tickers and at the same time, grab the stock prices from an API. Then, I store the stock prices into a new array and attempt to display the new array.

For example: An array element may contain 'AAPL' as a stock ticker. The for loop enters this element into the URL which links to an API, grabs the stock prices, stores it into a temporary variable. Then it stores the value (the stock price) of that temporary variable in to a new array. Then the new array will attempt to print out this stock price along with all the other stock prices.

Here is my code:
 
public static void getStock(String[] tickers) {  
for (i = 0; i < tickers.length; i++) {
try {
URL url = new URL("http://query.yahooapis.com/v1/public

[Code] .....

The above code works fine if I am printing the stock prices from inside the for loop. And I can see why, it enters and prints the new stock price in the new array through each loop.

My problem is, I do not know how to access the new array (stockOutput) outside of the for loop, or how to display its contents outside of the for loop.

View Replies View Related

I/O / Streams :: Select Multiple Files And Uploading Using Single Browse Option?

May 22, 2014

My requirement is - I need to browse the folder and select multiples and upload all the selected files at once. note that here i need to use single browse button ONLY.

View Replies View Related

ArrayList Only Adding 1 Item Even Though There Are Multiple Items (Setting Data To Files)

Oct 25, 2014

I managed to retrieve data, and set data in my own ways in which I like. But my problem is, if the file does not contain anything (fully empty), when I try to use my

set("", "");

method, it only sets the last one that is called.

Example:

set("section1", "section1Item");
set("section2", "section2Item");
set("section3", "section3Item");

Only section3 would get set, and not the others.

Otherwise, if the file contained a section already, then each section (section1, section2, section3) would get set.

Here's how I set the data to the file:

public static void set(String section, String data) {
files.openFileWriter();
files.file.delete();
reCreateFile();
String beforeItem = section + ":" + files.dataList.get(section);

[code]....

And here is how a retrieve the data and set them to my arraylist/hashmap:

public void getData() {
String line = null;
openFileReader();
StringBuffer sb = new StringBuffer();

[code]....

View Replies View Related

Reading Multiple Text Files From A Folder - Cannot Resolve Syntax Error

Apr 29, 2015

In the current program I am trying to read multiple text files from a folder. I keep getting the following syntax error

"Syntax error on token ";", { expected after this token".

I highlighted the line where im getting this error in red.
 
import java.io.*;
import java.util.*;
 public class CacheData {
  // Directory path here
    String path = "C:myfiles*.txt";
 
[Code] ....

View Replies View Related

While Loop To Perform Multiple Steps

Mar 20, 2014

Write a program that uses a while loop to perform the following steps: Comment by labelling each part: //Part A, //Part B, etc...

A.)Prompt the user to input 2 integers: firstNum and secondNum. Use 10 and 20.
B.)Output all odd numbers between firstNum and secondNum.
C.)Output the sum of all even numbers between firstNum and secondNum.
D.)Output the numbers and their square between 1 and 10.
E.)Output the sum of the square of odd numbers between firstNum and secondNum.
F.)Output all uppercase letters.

Again I am new to while loops and I am totally lost. I have just completed 8 other programs using if else statements and now trying to get the hang of loops.

import java.util.Scanner;
public class whileLoop {
public static void main(String[] args)

[code]...

View Replies View Related

Creating Multiple JTextFields In A Loop

Sep 18, 2014

I need to create a JFrame with a user given amount of text fields in the form of a matrix. Say the user inputs 5 rows and 5 columns, I need to read those ints and create a 5 by 5 box of JTextFields in matrix form (i.e. 25 total text boxes in the form of a box). Here is some of the code I have been trying to use to do this...

int x = 10;
int y = 10;
for(int i = 0; i<rowSize; i++){
y= y+40;
for(int k =0; k<colSize; k++) {
newField = new JTextField("0");
newField.setBounds(x,y,40,20);
win2.add(newField,0);
win2.repaint();
x= x+60;
}
}

In order to go through the loop a given amount of times and create that amount of text fields in the correct places.Am I even close to doing this right?? Cuz I can't get the text fields to even show up on my window.

View Replies View Related

Java - Going Through Value In Multiple ArrayList (Nested For Loop)

Jan 24, 2014

I just started playing around with Java for awhile, but got caught up in a problem when using ArrayList.

CinemaAppMain
public class CinemaAppMain {
public static void main(String[] args) {
new CinemaApp().start();

[Code]....

I am trying to get the movie name and theatre title from their ArrayList, and I know I need to go through the movie list & theatre list to find their name & title, and compare it with the user input and print out the result.

I use for(int i=0;i<movies.size();i++) to go through the the movie list, and I tried using for(int i=0;i<theatres.size();i++) to go through the theatre list. But when I printing multiple time with different user input value, it will show me strange result (screening have same movie name & theatre name, the else if statement is printed below the user input, user input is printed more than once after the first time).

Edit: I know its wrong for me to use nested for loop,if not, another solution is needed to get the item inside both of the list. (getting the "title" from movie list & "name" from theatre list)

View Replies View Related

Java Statement Getting Executed Multiple Times Outside For / While Loop

Aug 14, 2014

I am trying to execute the following method: This method takes a delivery date as one of the arguments and a list of calendar holidays as another argument. If the delivery date is present in the holiday list, I will add 1 day more to the delivery date and check again if the new delivery date is part of holiday list.

Issue is that the last 3 statements before 'return' are getting executed multiple times though there is no for or while loop. Why they are getting invoked multiple times.

@SuppressWarnings("rawtypes")
private String fetchNextWorkingDay(String sDeliveryDate, Element eleCalendarDayExceptions, SimpleDateFormat sdf, Format formatter) throws Exception {
System.out.println("");
System.out.println("Inside fetchNextWorkingDay method");
System.out.println("Del Date to compare is "+sDeliveryDate);
Boolean isDateSet = true;

[Code] .....

View Replies View Related

Window Closing Event

May 20, 2014

I have a WindowClosing(WindowEvent e) method, but when I close my window it isn't doing anything inside the method. I am making a launcher and I want to make it so when the actual game window is closed it makes the launcher window visible again.

Java Code: public void windowClosing(WindowEvent e) {
this.jf.setVisible(true);
} mh_sh_highlight_all('java');

View Replies View Related

How To Send A File Without Closing The Socket

Mar 3, 2014

I wrote a program to transfer a file using tcp connection, where I closed socket since the receiver need to detect the end-of--file.  But now I like to extend it to multiple file for which i should not close the socket until all the files are send. I can't find a way for this. So how to resolve it.

View Replies View Related

Setting Image Icon And Closing Up A Game

Jan 23, 2014

I recently made a game. But, I want to package it and give it to my friends. I know that I can create a jar of it and add the images to the folder, but what I would absolutely love is for it to just be a picture with the game name and click to run. The second thing is to replace that java icon to an icon of my preference, which I have been told numerous times to do with

frame.setIconImage(Image image)

which does not work for me.

View Replies View Related

Swing/AWT/SWT :: Closing Another Application Using Java Code

Feb 21, 2014

Following code I use to run or Launch another application

try {
Runtime.getRuntime().exec("rundll32 url.dll, FileProtocolHandler " + "Path of Application's EXE File");
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e, null, JOptionPane.ERROR_MESSAGE);
}

if the above code is to launch another application using java then how can I close/exit the same(another) application using java code once I press the exit button of my java app.

View Replies View Related

Closing JDialog Window When Press A JButton

Apr 11, 2015

I show a JDialog window and this window has 3 buttons when I press one of them it should close the window, how do I do that?

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved