Here's my code:
public void readFile() throws IOException {
System.out.println("Input file name: ");
Scanner in = new Scanner(System.in);
String readName = in.nextLine();
Scanner reader = new Scanner(new File(readName));
System.out.println("Reading file...");
while (reader.hasNextLine()) {
System.out.println(reader.nextLine());
}
System.out.println("File read.");
Scanner inAgain = new Scanner(System.in);
System.out.println("Would you like to read this into the current Diary?");
System.out.println("Warning: This will overwrite your current Diary!");
String readFileConfirm = inAgain.nextLine();
ArrayList<String> readData = new ArrayList<String>();
if (readFileConfirm.equalsIgnoreCase("yes")) {
for (int i = 0; i < readData.size(); i++) {
readData.add(reader.nextLine());
}
System.out.println("Data added to extra array...");
System.out.println("Here are the contents.");
for (int i = 0; i < readData.size(); i++) {
System.out.println(readData.get(i));
}
System.out.println("Contents read.");
System.out.println("Now overwriting current Diary with read file...");
diary.clear();
for (int i = 0; i < diary.size(); i++) {
diary.add(readData.get(i));
}
System.out.println("New Diary created!");
System.out.println("Use 'recall' to see your new Diary!");
} else {
System.out.println("Very well, returning to first command entry.");
}
}
Thanks in advance!
-h
Hey guys,
Kind of a strange question but... here it goes.
Recently my application threw an IOException that the text only had a clubs symbol in it (like the suit in cards) I know this is probably because there was a number in there that was cast to a char and printed to the screen, and I've found where that might have happened. The only problem is, I can't recreate it in eclipse because the eclipse console doesn't want to print those characters for me. All I get are boxes.
I figure this is an encoding issue or something but I need eclipse to print out those characters just like the windows console would. Is there a setting I can change to do this?
I'm running program at apache tomcat server, that should be on permanently, but every morning(the client part isn't accessible at night) i receive error message (in apache tomcat console) that MySQL server is off. So is there any way to prevent this?
Thanks in advance!
this.size = 9;
this.populationSize = 10;
Random rand = new Random();
Integer[][] easy1 = new Integer[size][size];
easy1 = this.initializeEasy1(easy1);
this.sudokuArray = new Sudoku[this.populationSize];
for (int i = 0; i < this.sudokuArray.length; i++){
long seed = rand.nextLong();
System.out.println("" + seed);
this.sudokuArray[i] = new Sudoku(easy1, this.size, seed);
}
I am building an evolutionary sudoku solver and I am having a problem where the last Sudoku object is overwriting all the other objects in the array. Where in the code did I mess up?
/edit here is the constructor of the class
public Sudoku(Integer[][] givensGrid, int s, long seed){
this.size = s;
this.givens = givensGrid;
this.grid = this.givens.clone();
Random rand = new Random(seed);
System.out.println("Random " + rand.nextInt());
// step though each row of the grid
for (int i = 0; i < size; i++){
ArrayList<Integer> numbers = new ArrayList<Integer>();
numbers = this.makeNumbers(numbers);
// step through each column to find the givens and remove from numbers
for (int j = 0; j < size; j++){
if (this.grid[i][j] != 0){
numbers.remove(this.grid[i][j]);
}
}
// go back through the row and assign the numbers randomly
for (int j = 0; j < size; j++){
if (this.grid[i][j] == 0){
int r = rand.nextInt(numbers.size());
this.grid[i][j] = numbers.get(r);
numbers.remove(r);
}
}
}
System.out.println("=============");
System.out.println(this.toString());
}
I use a Socket-based connection between Client and server with ObjectOutputStream.
The objects serialized and exchanged have this structure:
public class RichiestaSalvataggioArticolo implements Serializable {
private ArticoloDati articolo;
public RichiestaSalvataggioArticolo(ArticoloDati articolo) {
this.articolo = articolo;
}
@Override
public void ricevi(GestoreRichieste gestore) throws Exception {
gestore.interpreta(this);
}
public ArticoloDati getArticolo() {
return articolo;
}
}
the issue is that when I try to exchange messages between C/S with incapsulated content very similar (ArticoloDati whom differ only in 2 fields out of 10), the Client sends an ArticoloDati, but the Server receives the previous one.
Does the ObjectOutputStream implement some kind of cache or memory between the calls, that fails to recognize that my 2 objects are different because they are very similar?
I posted a question about how to rotate a tile in BufferedImage. I did it in the morning and you removed it. Why have you removed it again?
What is wrong with the posts?
Tell me before i become angry.
You have removed the post twice without informing/telling me the problem.
with the posts
What is wrong?
Tell me.
Reply to this post and tell me what is wrong.
I would like to be able to retrieve from my com.google.collections.Multimap<A, B> a Collection<Entry<A, Collection<B>>> which I expected from the entries() method, but in fact it returns a Collection<Entry<A, B>>. Is there a method which does what I want?
Sir,
We are working on a project.Here we encountered with a problem ie we are unable to include more than two panels on the same frame .What we want is one panel above the other. Can you please help us with this?
Hi everyone,
I want to generate html table in my jsp witch display values selected before submitting to allow user to know what did he puts into the form.
So I finish the form when submitting the values are inserted in database.
Now I search the possibility to display in the same jsp of the form the table having all the values selected.
So it is possible ton allow to actions in the form tag to insert and display from database at the same time.
Many Thanks for your help.
I would like to implement a method that can get the svn revision number from the path where a SVN repository has been checked out. The method declaration would look something like this:
long getRevisionNumber(String localPath) { ... }
I'm trying to use SVNKit for this, but it seems to require an SVN URL to start with. Is there any way to start with a local path?
The first index is set to null (empty), but it doesn't print the right output, why?
//set the first index as null and the rest as "High"
String a []= {null,"High","High","High","High","High"};
//add array to arraylist
ArrayList<Object> choice = new ArrayList<Object>(Arrays.asList(a));
for(int i=0; i<choice.size(); i++){
if(i==0){
if(choice.get(0).equals(null))
System.out.println("I am empty"); //it doesn't print this output
}
}
I'm puzzled with this.
In my machine
Direct calculation: 375 ms
Method calculation: 3594 ms, about TEN times SLOWER
If I place the method calulation BEFORE the direct calculation, both times are SIMILAR.
Woud you check it in your machine?
class Test {
static long COUNT = 50000 * 10000;
private static long BEFORE;
/*--------METHOD---------*/
public static final double hypotenuse(double a, double b) {
return Math.sqrt(a * a + b * b);
}
/*--------TIMER---------*/
public static void getTime(String text) {
if (BEFORE == 0) {
BEFORE = System.currentTimeMillis();
return;
}
long now = System.currentTimeMillis();
long elapsed = (now - BEFORE);
BEFORE = System.currentTimeMillis();
if (text.equals("")) {
return;
}
String message = "\r\n" + text + "\r\n" + "Elapsed time: " + elapsed + " ms";
System.out.println(message);
}
public static void main(String[] args) {
double a = 0.2223221101;
double b = 122333.167;
getTime("");
/*--------DIRECT CALCULATION---------*/
for (int i = 1; i < COUNT; i++) {
Math.sqrt(a * a + b * b);
}
getTime("Direct: ");
/*--------METHOD---------*/
for (int k = 1; k < COUNT; k++) {
hypotenuse(a, b);
}
getTime("Method: ");
}
}
Which software is recommended?
I know of Adobe Browser Lab only, and it seems pretty new... Is there any better SW out there?
Thanks
PS: I have a classifieds website (PHP, MySql, Solr, js) developed on local computer using virtual server etc... Now I need to test it on different browsers. It is developed only with Firefox, so it works fine in FF.
i have a table and the content of it is all from data base ,which is a rows of student names and a columns of questions, and with this table an instructor can track the students progress of solving question on real time, so what i want is to update the only the table , without refreshing the whole page, which causes starting at the beginning of the page so it would distract the instructor,,
any suggestion
I have a entity manager em1 .em1 starts a transcation tx on db1 table1.Now inside tx i call a API getdata().This API creastes a new entitymanger em2 and return 1 record.Now if entity manger em1 tries to delete the record returned by em1 , it hangs.Code times out.Is the record locked by em1.How can ii solve this problem?
create em1
//em1 start transcation tx1
tx1.start
Object r = getData();
em1 tried to delete r //code hangs here
tx1.commit
Object getData(){
create em2
return data found using em2
}
If I have Map setup like:
map.put("foo", "123");
map.put("bar", "456");
map.put("baz", "789");
then I want to do something like:
for (String key : map.keySet().toArray(new String[0])) {
// marshall out to .xml a tag with the name key and the
// value map.get(key)
}
So what it will marshal out is something like:
<map>
<foo>123</foo>
<bar>456</bar>
<baz>789</baz>
</map>
Can I do this with some fancy JAXB annotations or is there something else that lends it self to dynamic element names?
TIA
Hello,
I have JTextPane on my window and i have JTextField. When i press enter enter in JTextField, the text gets added in JTextPane. Everything works fine and scrollbar too appears on its own. But, it doesn't appear properly. It automatically scrolls to the beginning of the content in JTextPane. How do i keep the scrollbar to the end of JTextPane?
Please let me know if my question is unclear. Thanks in advance :)
Using Seam 2.1.2 and JSF 1.2 I wonder how to store the users login name in the database.
In plain JSF I would simply lookup FacesContext.getCurrentInstance().getExternalContext().getRemoteUser();in a backing bean and set the value into a persistent object.
How can I achieve that the users name will be stored in the DB?
I am creating a JButton which includes a specific ImageIcon. The main issue is that the original icon size is much bigger than the button size. As result when the button is displayed, only part of the icon can be seen. What is the method that "resize" an ImageIcon i n order to make it fit inside a JButton?
Am I only one complaining? It will be nice to go to error (Ctrl . takes to warnings and error). Also nice to able to do Auto complete a statement. Any other ideas?
Using JDO / DataNucleus / NeoDatis datastore
I added @Unique to a field of a persistable object, however I am allowed to create multiple objects which violate the unique constraint. The docs for DataNucleus/NeoDatis suggest that Unique fields are supported.
@PersistenceCapable
public class User {
@Persistent
@Unique
private String username;
//...
}
If I add multiple objects to the DB with the same username there's no problem doing so. :(
I would like to send a html string with a GET request like this with Apaches HttpClient:
http://sample.com/?html=<html><head>...
This doesnt work at the moment, i think its an encoding problem. Do you have any ideas how to do that?
method.setQueryString(new NameValuePair[] {new NameValuePair("report", "<html>....")});
client.executeMethod(method)
This fails with org.apache.commons.httpclient.NoHttpResponseException: The server localhost failed to respond. If i replace "<html>" by "test.." it works fine.
EDIT
It seams to be a problem of URL length after encoding, the server doesnt except such long URls. Sending it as POST solves the problem.