|
Hi,
I'm reading a .jsp page to a Outfile. I need to search for Text inside the Outfile so that I can replace the text with something else.
Does anyone have an idea how to do this?
Thanks
Mbu
|
|
|
|
|
import java.io.*;
import java.util.*;
public class ReadAndChange
{
public static void main(String[] args) throws Exception
{
Scanner scan = new Scanner(System.in);
System.out.println("Enter file Name:");
File theFile = new File(scan.next());
Scanner scan2 = new Scanner(theFile);
PrintWriter out = new PrintWriter(new File("out.format"));
while(scan2.hasNext())
{
String q = scan2.nextLine();
if (q.equalsIgnoreCase(""))
{
out.println("The result of manipulation");
}
else
out.println(q);
}
out.close();
}
}
Hope this helps
|
|
|
|
|
Hi All,
I am having problem getting values from jinternalframe, what i am doing is i got a JFrame that opens multiple JInternalFrame with JTextfield in it, now i want to get all the JTextfield value in the JInternalFrame, i need the function to be in the JFrame, is this possible, if not any recommendation is appreciated.
Thanks.
Stephen Michael
---------------------
www.islasolutions.net
|
|
|
|
|
In this code I show you the way to get the value for one all you need to do next is a simple loop to get the other values. This can be done by keeping a counter for the number of internal frames you have (make sure the JTextFields have consistent naming) then use a for loop to concatenate the values and display them in the label.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class InternalFrameExample extends JFrame
{
JLabel l;
JInternalFrame g;
JTextField t;
JButton b;
public InternalFrameExample()
{
g = new JInternalFrame();
t = new JTextField();
g.add(t, BorderLayout.NORTH);
g.setVisible(true);
g.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
l = new JLabel();
b = new JButton("poke");
b.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
l.setText(t.getText());
}
});
add(l, BorderLayout.NORTH);
add(b, BorderLayout.SOUTH);
add(g, BorderLayout.CENTER);
setTitle("InternalFrameExample");
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(400, 400);
}
public static void main(String[] args)
{
new InternalFrameExample();
}
}
Hope this helps
|
|
|
|
|
Hey guys,
I am working on an assignment that concerns itself with recursion. My program compiles, but does not run properly. The program is similar to checking that a string is a palindrome, but it is a little different. This program is supposed to check that each character in the string has a correct corresponding character. For example, in this assignment A's pair with T's and C's pair with G's. So the input AATT should be evaluated as a biopalindrome. My program runs correctly if I input a string that does not contain any A's, T's, C's or G's, but if I input the above expression, AATT, the error message I receive when the program runs is this:
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 4
at java.lang.String.charAt(String.java:558)
at bioPalindrome.checkPalindrome(bioPalindrome.java:42)
at bioPalindrome.checkPalindrome(bioPalindrome.java:45)
at bioPalindrome.checkPalindrome(bioPalindrome.java:45)
at bioPalindrome.checkPalindrome(bioPalindrome.java:45)
at bioPalindrome.checkPalindrome(bioPalindrome.java:45)
at bioPalindrome.main(bioPalindrome.java:24)
Here is the code that I have so far:
import java.util.Scanner;
public class bioPalindrome {
public static void main(String[] args) {
Scanner console = new Scanner(System.in);
System.out.println("Please enter the DNA string to be examined.");
String dnaString = console.nextLine();
dnaString = dnaString.toUpperCase();
System.out.println(dnaString + " " + dnaString.length());
boolean isPalindrome = checkPalindrome(dnaString, 0, dnaString.length());
if(isPalindrome == true)
System.out.println("The DNA string entered is a biopalindrome.");
else
System.out.println("The DNA string entered is not a biopalindrome.");
}
public static boolean checkPalindrome(String stringIn, int start, int end) {
if(stringIn.length() - 1 == 0 && start == end)
return true;
else if(stringIn.charAt(start) == 'A' && stringIn.charAt(end - 1) == 'T' || stringIn.charAt(start) == 'T' && stringIn.charAt(end - 1) == 'A' || stringIn.charAt(start) == 'C' && stringIn.charAt(end - 1) == 'G' || stringIn.charAt(start) == 'G' && stringIn.charAt(end - 1) == 'C') {
start++;
end--;
return checkPalindrome(stringIn, start, end);
} else
return false;
}
}
I appreciate any help or suggestions anyone can offer. Thanks again for your help.
|
|
|
|
|
Hey guys,
I made a small change and the code seems to be working properly now. The revision I made is that in the user-defined method, checkPalindrome, I changed the first conditional statement to if(start == end). So instead of
if(stringIn.length() - 1 == 0 && start == end)
The code now reads
if( start == end)
I'll try some more combinations and if I find an error, I'll post back.
|
|
|
|
|
Does Code Project have ongoing projects which one can participate in like a spectator or also join the coding team?
Is it possible to download project source code from a project on code project.
Priety.
|
|
|
|
|
prietycool wrote: Is it possible to download project source code from a project on code project.
Yes, see these articles[^].
|
|
|
|
|
Hi,
I want to participate in a java web project which uses springs and hibernate.
So that I can learn to configure and use springs and hibernate in a web project.
Is this possible on code project?
Priety.
|
|
|
|
|
|
We have to use different sorting algorithms to sort an array. So I already got the quick, bubble, and insertion sort working and I am not posting the code since it already works However the Merge Sort is giving me problems. I already searched online but could not find the right answer. Anyway...here it goes. We were provided with some code snippets and have to make them work. What data do they want when they say min, max? I thought that it would be the first element in the array and the last....No? cause its not working like that. Here is my code please someone help me what they want...
import java.io.*;
import java.util.*;
class MergeSortArray
{
public static void main(String[] args)
{
int choice = 0;
int[]values;
int counter = 0;
int backCounter = 10;
values = new int[10];
while(counter != 10)
{
Scanner scanner = new Scanner (System.in);
System.out.println("Enter " + backCounter + " more integers:");
choice = scanner.nextInt();
values[counter] = choice;
counter++;
backCounter--;
}
System.out.println(counter);
mergeSort (values, 0, values.length-1);
merge (values, first, mid, last);
int i=0;
while(i<10)
{
System.out.println(values[i]);
i++;
}
}
public static void mergeSort (Comparable[] data, int min, int max)
{
if (min < max)
{
int mid = (min + max) / 2;
mergeSort(data, min, mid);
mergeSort(data, mid+1, max);
merge (data, min, mid, max);
}
}
public static void merge (Comparable[] data, int first, int mid, int last)
{
Comparable[] temp = new Comparable[data.length];
int first1 = first, last1 = mid;
int first2 = mid + 1, last2 = last;
int index = first1;
while (first1 <= last1 && first2 <= last2)
{
if (data[first1].compareTo(data[first2]) < 0)
{
temp[index] = data[first1];
first1++;
}
else
{
temp[index] = data[first2];
first2++;
}
index++;
}
while (first1 <= last1)
{
temp[index] = data[first1];
first1++;
index++;
}
while (first2 <= last2)
{
temp[index] = data[first2];
first2++;
index++;
}
for (index = first; index <= last; index++)
data[index] = temp[index];
}
}
Please help me to get this working. Pretty Please!!!
|
|
|
|
|
1. Did you revise what your teacher said about merge sort.
2. Min is the smallest value in the array and Max is the biggest value in the array.
I did not check your code but here is a nice working example:
http://www.cs.colorado.edu/~main/applications/Mergesort.java[^]
In line 42 modify it to mergesort(data, 0, data.length);
Good luck
|
|
|
|
|
Member 4277480 wrote: In line 42 modify it to mergesort(data, 0, data.length);
Thanks for the answer. But from what I can see this is pretty much what I have.
mergeSort (values, 0, values.length-1);
Here is the error message I am getting maybe this will help
MergeSortArray.java:30: mergeSort(java.lang.Comparable[],int,int) in MergeSortArray cannot be applied to (int[],int,int)
|
|
|
|
|
Doh got it fixed had to change comparable [] to int[] ...silly mistake.
|
|
|
|
|
By the way the line I told you to change was from the link I told you about not yours
Any way good to hear you got it to work.
Regards
|
|
|
|
|
Member 4277480 wrote: By the way the line I told you to change was from the link I told you about not yours
Yeah I figured this out after starring at it for a bit!
But now I have another issue. I commented it with a bunch of ***** where the error is.
import java.io.*;
import java.util.*;
class MergeSortArray
{
public static void main(String[] args)
{
int choice = 0;
int[]values;
int counter = 0;
int backCounter = 10;
values = new int[10];
while(counter != 10)
{
Scanner scanner = new Scanner (System.in);
System.out.println("Enter " + backCounter + " more integers:");
choice = scanner.nextInt();
values[counter] = choice;
counter++;
backCounter--;
}
System.out.println(counter);
mergeSort (values, 1, values.length-1);
int i=0;
while(i<10)
{
System.out.println(values[i]);
i++;
}
}
public static void mergeSort (int[] data, int min, int max)
{
if (min < max)
{
int mid = (min + max) / 2;
mergeSort(data, min, mid);
mergeSort(data, mid+1, max);
merge (data, min, mid, max);
}
}
public static void merge (int[] data, int first, int mid, int last)
{
int[] temp = new int[data.length];
int first1 = first, last1 = mid;
int first2 = mid + 1, last2 = last;
int index = first1;
while (first1 <= last1 && first2 <= last2)
{
if (data[first1].compareTo(data[first2]) < 0)
{
temp[index] = data[first1];
first1++;
}
else
{
temp[index] = data[first2];
first2++;
}
index++;
}
while (first1 <= last1)
{
temp[index] = data[first1];
first1++;
index++;
}
while (first2 <= last2)
{
temp[index] = data[first2];
first2++;
index++;
}
for (index = first; index <= last; index++)
data[index] = temp[index];
}
}
I get the error MergeSortArray.java:72: int cannot be dereferenced
I tried changing:
if (data[first1].compareTo(data[first2]) < 0)
to
;if (data[first1]== data[first2] < 0)
But that did not work either. Any idea how I would code this right?
|
|
|
|
|
import java.io.*;
import java.util.*;
class MergeSortArray
{
public static void main(String[] args)
{
int choice = 0;
Comparable[] values;
int counter = 0;
int backCounter = 10;
values = new Comparable[10];
while (counter != 10)
{
Scanner scanner = new Scanner(System.in);
System.out.println("Enter " + backCounter + " more integers:");
choice = scanner.nextInt();
values[counter] = choice;
counter++;
backCounter--;
}
mergeSort(values, 0, values.length - 1);
System.out.println();
int i = 0;
while (i < 10)
{
System.out.print(values[i] + " ");
i++;
}
}
public static void mergeSort(Comparable[] data, int min, int max)
{
if (min < max)
{
int mid = (min + max) / 2;
mergeSort(data, min, mid);
mergeSort(data, mid + 1, max);
merge(data, min, mid, max);
}
}
public static void merge(Comparable[] data, int first, int mid, int last)
{
Comparable[] temp = new Comparable[data.length];
int first1 = first, last1 = mid;
int first2 = mid + 1, last2 = last;
int index = first1;
while (first1 <= last1 && first2 <= last2)
{
if (data[first1].compareTo(data[first2]) < 0)
{
temp[index] = data[first1];
first1++;
}
else
{
temp[index] = data[first2];
first2++;
}
index++;
}
while (first1 <= last1)
{
temp[index] = data[first1];
first1++;
index++;
}
while (first2 <= last2)
{
temp[index] = data[first2];
first2++;
index++;
}
for (index = first; index <= last; index++)
data[index] = temp[index];
}
}
Well you had some mistakes but all is well now.
|
|
|
|
|
Thanks so much. I was so close. It all works now. I appreciate it.
~Silke~
|
|
|
|
|
Hi all,
I have the following function call that returns a string value after encryption or decryption. My problem is how to write this string value to a text file.
String outStr= RunRC4(InputFile,aKey);
try {
BufferedWriter out = new BufferedWriter(new FileWriter(args[2], true));
out.write(outStr + "\n");
out.close();
} catch (Exception e) {
System.err.println(e.getMessage());
}
public static String RunRC4(String InputFile,String aKey)
Can anyone help?
Thanks in advance!!!
|
|
|
|
|
import java.io.*;
public class FileWrite
{
public static void main(String[] args) throws Exception
{
PrintWriter out = new PrintWriter(new File("test.text"));
out.print("The String Value");
out.close();
}
}
Good luck
|
|
|
|
|
how to move cookie value from https to http page? In my project, login page is in https.and page of after login is in http.here the i cant get cookie value.Is there any solution?Please help me.
modified on Friday, September 18, 2009 4:16 AM
|
|
|
|
|
Wrong forum. Try asking in web development.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
Using Cookies That Are Transmitted by Both HTTP and HTTPS
Because HTTP and HTTPS requests are sent to different ports, some browsers may not include the cookie sent in an HTTP request with a subsequent HTTPS request (or vice-versa). This may cause new sessions to be created when servlet requests alternate between HTTP and HTTPS. To ensure that all cookies set by a specific domain are sent to the server every time a request in a session is made, set the cookie-domain element to the name of the domain. The cookie-domain element is a subelement of the session-descriptor element in the WebLogic-specific deployment descriptor weblogic.xml. For example:
<session-descriptor>
<cookie-domain>mydomain.com</cookie-domain>
</session-descriptor>
The cookie-domain element instructs the browser to include the proper cookie(s) for all requests to hosts in the domain specified by mydomain.com. For more information about this property or configuring session cookies, see Setting Up Session Management.[^]
from http://download.oracle.com/docs/cd/E13222_01/wls/docs90/webapp/progservlet.html[^]
Good Luck
|
|
|
|
|
Thank u.I am using apache tomcat server.here what will i do?
|
|
|
|
|
Hi all !
I want use FreeTTS for my application. I can use the code bellow to read the Hello World in English.
How can i read another language for example German or French,...
My code here :
package com.myprj.demo;
import java.io.File;
import java.io.PrintStream;
import java.util.Locale;
import javax.speech.Central;
import javax.speech.EngineList;
import javax.speech.synthesis.*;
public class HelloWorld
{
public HelloWorld()
{
}
private static String noSynthesizerMessage()
{
String message = "No synthesizer created. This may be the result of any\nnumber of problems. It's typically due to a missing\n\"speech.properties\" file that should be at either of\nthese locations: \n\n";
message = message + "user.home : " + System.getProperty("user.home") + "\n";
message = message + "java.home/lib: " + System.getProperty("java.home") + File.separator + "lib\n\n" + "Another cause of this problem might be corrupt or missing\n" + "voice jar files in the freetts lib directory. This problem\n" + "also sometimes arises when the freetts.jar file is corrupt\n" + "or missing. Sorry about that. Please check for these\n" + "various conditions and then try again.\n";
return message;
}
public static void main(String args[])
{
String voiceName = args.length <= 0 ? "kevin16" : args[0];
System.out.println();
System.out.println("Using voice: " + voiceName);
try
{
SynthesizerModeDesc desc = new SynthesizerModeDesc(null, "general", Locale.GERMAN, null, null);
Synthesizer synthesizer = Central.createSynthesizer(desc);
if(synthesizer == null)
{
System.err.println(noSynthesizerMessage());
System.exit(1);
}
synthesizer.allocate();
synthesizer.resume();
desc = (SynthesizerModeDesc)synthesizer.getEngineModeDesc();
Voice voices[] = desc.getVoices();
Voice voice = null;
int i = 0;
do
{
if(i >= voices.length)
break;
if(voices[i].getName().equals(voiceName))
{
voice = voices[i];
break;
}
i++;
} while(true);
if(voice == null)
{
System.err.println("Synthesizer does not have a voice named " + voiceName + ".");
System.exit(1);
}
synthesizer.getSynthesizerProperties().setVoice(voice);
synthesizer.speakPlainText("Hello world", null);
synthesizer.waitEngineState(0x10000L);
synthesizer.deallocate();
System.exit(0);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
1.So if i want to the program read the "Datum" String in German my code must be change to :
<br />
SynthesizerModeDesc desc = new SynthesizerModeDesc(null, "general", Locale.GERMAN, null, null);<br />
<br />
synthesizer.speakPlainText("Datum", null);<br />
Is it ok or another ways?
2.How many languages FreeTTS support ? which are they?
Best regards !
|
|
|
|
|