Creating a String from an array of characters.

Hi,
i'm trying to make a string from an array of characters, this i've managed:
char data[] = new char[x];
String str = new String(data);My problem is this: Let's say the array of characters has space for 10 chars, but i only input 5, when i convert it to a string, the 5 characters show up fine, but the last remaining characters show up as little boxes ( [] [] [] [] [] ) .
It there a way to remove these?
Thanks in advance
Mike

jverd wrote:
georgemc wrote:
String str = new String(data).trim();
Does the null character count as whitespace?Seems to. Actually, I'm getting different results depending on the compiler used.
public static void main(String[] args) {
          char[] c = new char[10];
          for(int i = 0; i < 5; i++) {
               c[i] = (char) ('a' + i);
          String first = new String(c);
          System.err.println("[" + first  + "]");
          System.err.println(first.length());
          String second = new String(c).trim();
          System.err.println("[" + second  + "]");
          System.err.println(second.length());
     }ECJ-compiled output:
>
[abcde
10
[abcde]
5
>
javac-compiled output:
>
[abcde]
10
[abcde]
5
>
Odd

Similar Messages

  • How to improve the speed of creating multiple strings from a char[]?

    Hi,
    I have a char[] and I want to create multiple Strings from the contents of this char[] at various offsets and of various lengths, without having to reallocate memory (my char[] is several tens of megabytes large). And the following function (from java/lang/String.java) would be perfect apart from the fact that it was designed so that only package-private classes may benefit from the speed improvements it offers:
        // Package private constructor which shares value array for speed.
        String(int offset, int count, char value[]) {
         this.value = value;
         this.offset = offset;
         this.count = count;
        }My first thought was to override the String class. But java.lang.String is final, so no good there. Plus it was a really bad idea to start with.
    My second thought was to make a java.lang.FastString which would then be package private, and could access the string's constructor, create a new string and then return it (thought I was real clever here) but no, apparently you cannot create a class within the package java.lang. Some sort of security issue.
    I am just wondering first if there is an easy way of forcing the compiler to obey me, or forcing it to allow me to access a package private constructer from outside the package. Either that, or some sort of security overrider, somehow.

    My laptop can create and garbage collect 10,000,000 Strings per second from char[] "hello world". That creates about 200 MB of strings per second (char = 2B). Test program below.
    A char[] "tens of megabytes large" shouldn't take too large a fraction of a second to convert to a bunch of Strings. Except, say, if the computer is memory-starved and swapping to disk. What kind of times do you get? Is it at all possible that there is something else slowing things down?
    using (literally) millions of charAt()'s would be
    suicide (code-wise) for me and my program."java -server" gives me 600,000,000 charAt()'s per second (actually more, but I put in some addition to prevent Hotspot from optimizing everything away). Test program below. A million calls would be 1.7 milliseconds. Using char[n] instead of charAt(n) is faster by a factor of less than 2. Are you sure millions of charAt()'s is a huge problem?
    public class t1
        public static void main(String args[])
         char hello[] = "hello world".toCharArray();
         for (int n = 0; n < 10; n++) {
             long start = System.currentTimeMillis();
             for (int m = 0; m < 1000 * 1000; m++) {
              String s1 = new String(hello);
              String s2 = new String(hello);
              String s3 = new String(hello);
              String s4 = new String(hello);
              String s5 = new String(hello);
             long end = System.currentTimeMillis();
             System.out.println("time " + (end - start) + " ms");
    public class t2
        static int global;
        public static void main(String args[])
         String hello = "hello world";
         for (int n = 0; n < 10; n++) {
             long start = System.currentTimeMillis();
             for (int m = 0; m < 10 * 1000 * 1000; m++) {
              global +=
                  hello.charAt(0) + hello.charAt(1) + hello.charAt(2) +
                  hello.charAt(3) + hello.charAt(4) + hello.charAt(5) +
                  hello.charAt(6) + hello.charAt(7) + hello.charAt(8) +
                  hello.charAt(9);
              global +=
                  hello.charAt(0) + hello.charAt(1) + hello.charAt(2) +
                  hello.charAt(3) + hello.charAt(4) + hello.charAt(5) +
                  hello.charAt(6) + hello.charAt(7) + hello.charAt(8) +
                  hello.charAt(9);
             long end = System.currentTimeMillis();
             System.out.println("time " + (end - start) + " ms");
    }

  • How to delete string from an array

    I just want to know that what changes i can do to delete the string if contains any extra characters like digits and punctuation marks in the middle or begining of the string but not at the end of the string, i've already tried to delete only the punctuation marks at the end of the string and keep that word. Please dont forget that i m a beginer
    import java.io.*;
    import java.util.*;
    class Project
    public static void main()throws IOException
    // set up input stream
    File finput = new File("C:\\f1.txt");
    FileReader fr = new FileReader(finput);
    BufferedReader fin = new BufferedReader (fr);
    // set up output stream
    File foutput = new File("C:\\f3.txt");
    FileWriter fw = new FileWriter (foutput);
    PrintWriter fout = new PrintWriter (fw);
    String nextLine; // a line read from the file
    StringTokenizer t; // the words within the line
    ArrayList words = new ArrayList(); // an array of words
    //String n = {0,1,2,3,4,5,6,7,8,9};
    System.out.println("Reading file.\n");
    // start
    while (true)
    nextLine =fin.readLine(); // read from input file
    if (nextLine==null) break; // if no more lines, get out
    t = new StringTokenizer(nextLine); // identify words
    while (t.hasMoreTokens())
    String str = (String)t.nextToken();
    str = str.toLowerCase(); // Converting all uppercase to lowercase.
    // Replacing all punctuation marks.
    str=str.replace(',',' ');
    str=str.replace('?',' ');
    str=str.replace('!',' ');
    str=str.replace('.',' ');
    str=str.replace(':',' ');
    str=str.replace(';',' ');
    str=str.replace('"',' ');
    str=str.replace('"',' ');
    str=str.trim(); // Removing empty spaces after words
    words.add(str); // add them to array
    String z; // Declaring string z for sorting.
    for (int i=0; i<words.size(); i++)
    for (int j=i+1; j<words.size(); j++)
    // Sorting the Array list.
    if (((String)words.get(j)).compareTo((String)words.get(i))<0)
    z=(String)words.get(i);
    words.remove(i);
    words.add(i,(String)words.get(j-1));
    words.remove(j);
    words.add(j,z);
    // To replacing word which have got "'".
    if ((String)words.get(i)).indexOf("'")!=-1)
    a="";
    int count[]=new int[words.size()]; //Creating int array for counting the repetition.
    for (int i=0;i<=words.size()-1;i++)
    for (int j=i+1;j<=words.size()-1;j++)
    //Counting the repetition of the string.
    //if (((String)words.get(j)).compareTo((String)words.get(i))==0)
    if (((String)words.get(j)).equals((String)words.get(i))==true)
    count[i]++;
    words.remove(j);
    j=j-1;
    System.out.println("Dictionary\t|\tRepetition");
    System.out.println("==========\t \t==========\n");
    for (int i=0; i<words.size(); i++)
    count[i]++; // initialinzing the value with 1
    // Printing result on the output file.
    fout.println((String)words.get(i));
    // Printing result on the screen with histogram.
    System.out.println((String)words.get(i)+ "\t\t|\t" +count[i]);
    fout.close();
    System.out.println();
    System.out.println("Finished");
    } //end of main.

    The code that you pasted does not seem like written by a beginner. So, did you write the code?
    If so, you should have no problem solving this simple thing.
    If not, then copy and pasting a block of program that you don't understand will keep you as a beginner all the time, so can't help you if you are willing to stay at beginner.
    --lichu                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Create Class objects from an Array of File Objects

    Hi There,
    I'm having extreme difficulty in trying to convert an array of file objects to Class objects. My problem is as follows: I'm using Jfilechooser to select a directory and get an array of files of which are all .class files. I want to create Class objects from these .class files. Therefore, i can extract all the constructor, method and field information. I eventually want this class information to display in a JTree. Very similar to the explorer used in Netbeans. I've already created some code below, but it seems to be throwing a NoSuchMethodError exception. Can anyone please help??
    Thanks in advance,
    Vikash
    /* the following is the class im using */
    class FileClassLoader extends ClassLoader {
    private File file;
    public FileClassLoader (File ff) {
    this.file = ff;
    protected synchronized Class loadClass() throws ClassNotFoundException {
    Class c = null;
    try {
    // Get size of class file
    int size = (int)file.length();
    // Reserve space to read
    byte buff[] = new byte[size];
    // Get stream to read from
    FileInputStream fis = new FileInputStream(file);
    DataInputStream dis = new DataInputStream (fis);
    // Read in data
    dis.readFully (buff);
    // close stream
    dis.close();
    // get class name and remove ".class"
    String classname = null;
    String filename = file.getName();
    int i = filename.lastIndexOf('.');
    if(i>0 && i<filename.length()-1) {
    classname = filename.substring(0,i);
    // create class object from bytes
    c = defineClass (classname, buff, 0, buff.length);
    resolveClass (c);
    } catch (java.io.IOException e) {
    e.printStackTrace();
    return c;
    } // end of method loadClass
    } // end of class FileClassLoader
    /* The above class is used in the following button action in my gui */
    /* At the moment im trying to output the data to standard output */
    private void SelectPackage_but2ActionPerformed(java.awt.event.ActionEvent evt) {
    final JFileChooser f = new JFileChooser();
    f.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    int rVal = f.showOpenDialog(Remedy.this);
    // selects directory
    File dir = f.getSelectedFile();
    // gets a list of files within the directory
    File[] allfiles = dir.listFiles();
    // for loop to filter out all the .class files
    for (int k=0; k < allfiles.length; k++) {
    if (allfiles[k].getName().endsWith(".class")) {
    try {
    System.out.println("File name: " + allfiles[k].getName()); // used for debugging
    FileClassLoader loader = new FileClassLoader(allfiles[k]);
    Class cl = loader.loadClass();
    //Class cl = null;
    Class[] interfaces = cl.getInterfaces();
    java.lang.reflect.Method[] methods = cl.getDeclaredMethods();
    java.lang.reflect.Field[] fields = cl.getDeclaredFields();
    System.out.println("Class Name: " + cl.getName());
    //print out methods
    for (int m=0; m < methods.length; m++) {
    System.out.println("Method: " + methods[m].getName());
    // print out fields
    for (int fld=0; fld < fields.length; fld++) {
    System.out.println("Field: " + fields[fld].getName());
    } catch (Exception e) {
    e.printStackTrace();
    } // end of if loop
    } // end of for loop
    packageName2.setText(dir.getPath());
    }

    It's throwing the exeption on the line:
    FileClassLoader loader = new FileClassLoader(allfiles[k]);
    I'm sure its something to do with the extended class i've created. but i cant seem to figure it out..
    Thanks if you can figure it out

  • Using Javascript to create concatenated string from checkbox fields to one text field

    Hi. I have a PDF form that I am trying to have output to a spreadsheet that matches my database schema. Here is the dilemna:
    * I have a set of checkboxes for available languages (LANGUAGE_ENGLISH, LANGUAGE_SPANISH, etc.) When they export to spreadsheet, the value is TRUE.
    * I need to take values from checked boxes and create a single string in a text field called LANGUAGE_DISPLAY (so my UI will not need to do the concatenation). If LANGUAGE_ENGLISH is TRUE (checked), append "English, " to LANGUAGE_DISPLAY, else append "". Then, if LANGUAGE_SPANISH is TRUE (checked), append "Spanish, " to LANGUAGE_DISPLAY, else append "". And on and on
    In the LANGUAGE_DISPLAY text field properties, I am inserting a Custom Calculation script to try to achieve this, but am not getting any results. I tried teh following even trying to pull the checkboxes default values and string them together:
    box1 = this.getField("LANGUAGE_ENGLISH").value.toSrting();
    box2 = this.getField("LANGUAGE_FARSI").value.toSrting();
    box3 = this.getField("LANGUAGE_MANDARIN").value.toSrting();
    event.value = box1 + ', ' + box2 + ', ' + box3;
    I also played with this to get the desired strings output...but to no avail:
    if ( LANGUAGE_ENGLISH.rawValue == true )
    box1.rawValue = "English, ";
    if ( LANGUAGE_FARSI.rawValue == true )
    box1.rawValue = "Farsi, ";
    if ( LANGUAGE_HEBREW.rawValue == true )
    box1.rawValue = "Hebrew, ";
    event.value = box1 + box2 + box3;
    Then I tried to simplify to see one field output so used this script...still no results:
    event.value = "";
    var f = this.getField("LANGUAGE_ENGLISH");
    if ( f.isBoxChecked() == true) {
    event.value = "English";
    Couple questions:
    1) Am I on the right track with any of these scripts?
    2) Is there something else I need to do to get the script to run before running the Create Spreadsheet with Data Files comman in Acrobat to get my csv file output? Maybe there needs to be some event to get the checkbox values read by that field in order to calculate/create the string.
    Appreciate any help you can provide.

    LiveCycle Designer has shipped with all Acrobat Professional versions since the "Professional" version was introduced with version 6.
    You do not let us know want results you get in the field or the JavaScript console.
    Using:
    box1 = this.getField("LANGUAGE_ENGLISH").value.toString();
    box2 = this.getField("LANGUAGE_FARSI").value.toString();
    box3 = this.getField("LANGUAGE_MANDARIN").value.toString();
    event.value = box1 + ', ' + box2 + ', ' + box3;
    returns "Off, Off, Off", when no box is checked and returns "Yes" for the appropriate box being checked when the default value is used for the creation of the check box. So if one would make the 'Export Value' of the box from the default value of 'Yes" to the appropriate language, one would get a more desirable result. But for each unchecked box the value would appear as "Off". So one needs to change the 'Off' value to a null string. But one is still left with the separator when there is an unchecked option.
    Using the following document level function:
    // Concatenate 3 strings with separators where needed
    function fillin(s1, s2, s3, sep) {
    Purpose: concatenate up to 3 strings with an optional separator
    inputs:
    s1: required input string text or empty string
    s2: required input string text or empty string
    s3: required input string text or empty string
    sep: optional separator sting
    returns:
    sResult concatenated string
    // variable to determine how to concatenate the strings
    var test = 0; // all strings null
    var sResult; // re slut string to return
    // force any number string to a character string for input variables
    s1 = s1.toString();
    s2 = s2.toString();
    s3 = s3.toString();
    if(sep.toString() == undefined) sep = ''; // if sep is undefined force to null
    assign a binary value for each string present
    so the computed value of the strings will indicate which strings are present
    when converted to a binary value
    if (s1 != "") test += 1; // string 1 present add binary value: 001
    if (s2 != "") test += 2; // string 2 present add binary value: 010
    if (s3 != "") test += 4; // string 3 present add binary value: 100
    /* return appropriate string combination based on
    calculated test value as a binary value
    switch (test.toString(2)) {
    case "0": // no non-empty strings passed - binary 0
    sResult = "";
    break;
    case "1": // only string 1 present - binary 1
    sResult = s1;
    break;
    case "10": // only string 2 present - binary 10
    sResult = s2;
    break;
    case "11": // string 1 and 2 present - binary 10 + 1
    sResult = s1 + sep + s2;
    break;
    case "100": // only string 3 present - binary 100
    sResult = s3;
    break;
    case "101": // string 1 and 3 - binary 100 + 001
    sResult = s1 + sep + s3;
    break;
    case "110": // string 2 and 3 - binary 100 + 010
    sResult = s2 + sep + s3;
    break;
    case "111": // all 3 strings - binary 100 + 010 + 001
    sResult = s1 + sep + s2 + sep + s3;
    break;
    default: // any missed combinations
    sResult = "";
    break;
    return sResult;
    And the following cleaned up custom calculation script:
    box1 = this.getField("LANGUAGE_ENGLISH").value;
    box2 = this.getField("LANGUAGE_FARSI").value;
    box3 = this.getField("LANGUAGE_MANDARIN").value;
    if (box1 == 'Off') box1 = '';
    if (box2 == 'Off') box2 = '';
    if (box3 == 'Off') box3 = '';
    event.value = fillin(box1, box2, box3, ', ');
    One will get the list of languages with the optional separator for 2 or more language selections.

  • Create an image from float array?

    Dear All,
    I have a float array containing pixel values. From that array I want to create an image (let's say in JPEG format).
    How should I do that?
    thanks

    Hi musti168,
    You're going through your entire image pixel-by-pixel and getting each of their values - why don't you just use the IMAQ ImageToArray function?  
    On this forum post I found an example of IMAQ ArrayToImage: http://forums.ni.com/t5/LabVIEW/IMAQ-arraytoimage-​example/td-p/68418
    You can use some of the IMAQ Image Processing palette to change the image to gray scale - possibly a threshold.
    Julian R.
    Applications Engineer
    National Instruments

  • How to create XML string from BPM Business Object?

    Hello,
    I have a business object in my BPM project and I need to transform it in a XML string:
    From:
    Business Object: Customer
    Properties:          Name, Age
    To:
    "<Customer><Name>Robert</Name><Age>17</Age></Customer>"
    How can I do this?
    Thanks.

    Hello,
    I have a business object in my BPM project and I need to transform it in a XML string:
    From:
    Business Object: Customer
    Properties:          Name, Age
    To:
    "<Customer><Name>Robert</Name><Age>17</Age></Customer>"
    How can I do this?
    Thanks.

  • Create a string from characters

    Hi, I'd like to know if my code looks good.
    In these few lines there are a lot of new concepts for me, and being at the beginning with Java I'd like to have a supervision.
    It compiles and runs fine, but I don't know if I could semplify/improve it.
    private String computeMD5(Reader r) throws IOException
       try
          StringWriter fileContent = new StringWriter();
          int character;
          while ((character = r.read()) != -1)
             fileContent.write(character);
           return MD5sum(fileContent.toString());
       finally
          r.close();
    }Thanks

    It is unusual to do MD5 on a Reader since MD5 is designed for bytes and the MessageDigest class has methods for appending bytes. I would have expect an InputStream rather than a reader.
    I suspect that you are using the wrong approach but without seeing more code I can't be sure.
    P.S. I hope you don't convert your digest bytes to a String using
    String digestAsString = new String(digestAsBytes);

  • Creating a sound from an array of numeric values and playing it on speakers

    How do I create take a sound I have stored as an array (or could be an arraylist if needed) of numeric values (at the moment as doubles) whiten my program and output it to speakers? I am using blueJ.
    for example (0, 0.1, 0.4, 0.8, 0.9, 1, 0.8, 0.6, 0.3, 0.1, etc...) would be a very high frequency sin wave.
    Edited by: alan2here on Feb 6, 2008 11:28 AM

    I stumbled upon this thread with a question somewhat related:
    I've recorded a wave file from microphone. But what I would like is an array of numbers in the same way alan said. I'm also working on my own project involving signal processing (i'm trying to do speech recognition).
    I can't really find a nice way of getting that array of numbers. I've tried to find out how wave file stores it's data, and directly read from the File object, but i figured there should be an easier way...
    I used this code to read the sound:
    *     SimpleAudioRecorder.java
    *     This file is part of jsresources.org
    * Copyright (c) 1999 - 2003 by Matthias Pfisterer
    * All rights reserved.
    * Redistribution and use in source and binary forms, with or without
    * modification, are permitted provided that the following conditions
    * are met:
    * - Redistributions of source code must retain the above copyright notice,
    *   this list of conditions and the following disclaimer.
    * - Redistributions in binary form must reproduce the above copyright
    *   notice, this list of conditions and the following disclaimer in the
    *   documentation and/or other materials provided with the distribution.
    |<---            this code is formatted to fit into 80 columns             --->|
    import java.io.IOException;
    import java.io.File;
    import javax.sound.sampled.DataLine;
    import javax.sound.sampled.TargetDataLine;
    import javax.sound.sampled.AudioFormat;
    import javax.sound.sampled.AudioSystem;
    import javax.sound.sampled.AudioInputStream;
    import javax.sound.sampled.LineUnavailableException;
    import javax.sound.sampled.AudioFileFormat;
    public class SimpleAudioRecorder
    extends Thread
         private TargetDataLine          m_line;
         private AudioFileFormat.Type     m_targetType;
         private AudioInputStream     m_audioInputStream;
         private File               m_outputFile;
         public SimpleAudioRecorder(TargetDataLine line,
                             AudioFileFormat.Type targetType,
                             File file)
              m_line = line;
              m_audioInputStream = new AudioInputStream(line);
              m_targetType = targetType;
              m_outputFile = file;
         /** Starts the recording.
             To accomplish this, (i) the line is started and (ii) the
             thread is started.
         public void start()
              /* Starting the TargetDataLine. It tells the line that
                 we now want to read data from it. If this method
                 isn't called, we won't
                 be able to read data from the line at all.
              m_line.start();
              /* Starting the thread. This call results in the
                 method 'run()' (see below) being called. There, the
                 data is actually read from the line.
              super.start();
         /** Stops the recording.
             Note that stopping the thread explicitely is not necessary. Once
             no more data can be read from the TargetDataLine, no more data
             be read from our AudioInputStream. And if there is no more
             data from the AudioInputStream, the method 'AudioSystem.write()'
             (called in 'run()' returns. Returning from 'AudioSystem.write()'
             is followed by returning from 'run()', and thus, the thread
             is terminated automatically.
             It's not a good idea to call this method just 'stop()'
             because stop() is a (deprecated) method of the class 'Thread'.
             And we don't want to override this method.
         public void stopRecording()
              m_line.stop();
              m_line.close();
         /** Main working method.
             You may be surprised that here, just 'AudioSystem.write()' is
             called. But internally, it works like this: AudioSystem.write()
             contains a loop that is trying to read from the passed
             AudioInputStream. Since we have a special AudioInputStream
             that gets its data from a TargetDataLine, reading from the
             AudioInputStream leads to reading from the TargetDataLine. The
             data read this way is then written to the passed File. Before
             writing of audio data starts, a header is written according
             to the desired audio file type. Reading continues untill no
             more data can be read from the AudioInputStream. In our case,
             this happens if no more data can be read from the TargetDataLine.
             This, in turn, happens if the TargetDataLine is stopped or closed
             (which implies stopping). (Also see the comment above.) Then,
             the file is closed and 'AudioSystem.write()' returns.
         public void run()
                   try
                        AudioSystem.write(
                             m_audioInputStream,
                             m_targetType,
                             m_outputFile);
                   catch (IOException e)
                        e.printStackTrace();
         public static void main(String[] args)
              if (args.length != 1 || args[0].equals("-h"))
                   printUsageAndExit();
              /* We have made shure that there is only one command line
                 argument. This is taken as the filename of the soundfile
                 to store to.
              String     strFilename = args[0];
              File     outputFile = new File(strFilename);
              /* For simplicity, the audio data format used for recording
                 is hardcoded here. We use PCM 44.1 kHz, 16 bit signed,
                 stereo.
              AudioFormat     audioFormat = new AudioFormat(
                   AudioFormat.Encoding.PCM_SIGNED,
                   44100.0F, 16, 2, 4, 44100.0F, false);
              /* Now, we are trying to get a TargetDataLine. The
                 TargetDataLine is used later to read audio data from it.
                 If requesting the line was successful, we are opening
                 it (important!).
              DataLine.Info     info = new DataLine.Info(TargetDataLine.class, audioFormat);
              TargetDataLine     targetDataLine = null;
              try
                   targetDataLine = (TargetDataLine) AudioSystem.getLine(info);
                   targetDataLine.open(audioFormat);
              catch (LineUnavailableException e)
                   out("unable to get a recording line");
                   e.printStackTrace();
                   System.exit(1);
              /* Again for simplicity, we've hardcoded the audio file
                 type, too.
              AudioFileFormat.Type     targetType = AudioFileFormat.Type.WAVE;
              /* Now, we are creating an SimpleAudioRecorder object. It
                 contains the logic of starting and stopping the
                 recording, reading audio data from the TargetDataLine
                 and writing the data to a file.
              SimpleAudioRecorder     recorder = new SimpleAudioRecorder(
                   targetDataLine,
                   targetType,
                   outputFile);
              /* We are waiting for the user to press ENTER to
                 start the recording. (You might find it
                 inconvenient if recording starts immediately.)
              out("Press ENTER to start the recording.");
              try
                   System.in.read();
              catch (IOException e)
                   e.printStackTrace();
              /* Here, the recording is actually started.
              recorder.start();
              out("Recording...");
              /* And now, we are waiting again for the user to press ENTER,
                 this time to signal that the recording should be stopped.
              out("Press ENTER to stop the recording.");
              try
                   System.in.read();
              catch (IOException e)
                   e.printStackTrace();
              /* Here, the recording is actually stopped.
              recorder.stopRecording();
              out("Recording stopped.");
         private static void printUsageAndExit()
              out("SimpleAudioRecorder: usage:");
              out("\tjava SimpleAudioRecorder -h");
              out("\tjava SimpleAudioRecorder <audiofile>");
              System.exit(0);
         private static void out(String strMessage)
              System.out.println(strMessage);
    }Daniel

  • Create a string from HTML code

    Hello to all,
    What i have already create is a web browser integrate into a VI project and from this i can read some values like temperature or humidity. Also i have put a HTML window in order to take this values and to export to a string (for example to check these values from the browser and to be able to see in separate constat). Can you help how to do this with an example??
    Thanks in advance

    Below i have attached the code and the HTML code from the sensor. If you have to recommend anything it will be usefull for me. I have another problem now. If you see in the HTML code you will see that i have three different values to export(temperature, humidity and dewpoint) but all of them have the same regular expression in order to request in my code. Do you know how is it possible to solve this problem because always i take the same temperature value for three of them.
    Thanks in advance
    Attachments:
    TempHumid.vi ‏41 KB
    HTMLcode.jpg ‏68 KB

  • How to create two String from ResultSet to arraylist?

    Hi,
    Here is my question:
    String sql = "select colA, colB from tblA";
    String str1 = null;
    String str2 = null;
    ArrayList al = null;
    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery(sql);
    while(rs.next()){
              str1 = rs.getString("colA");
              str2 = rs.getString("colB");
    }May i know how can i set the str1 and str2 in the ArrayList al?
    Thanks.

    Hi,
    Here is my question:
    String sql = "select colA, colB from tblA";
    String str1 = null;
    String str2 = null;
    ArrayList al = null;
    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery(sql);
    while(rs.next()){
    str1 = rs.getString("colA");
    str2 = rs.getString("colB");
    May i know how can i set the str1 and str2 in the
    ArrayList al?
    Thanks.
    is this what you're looking for?
    al = new ArrayList();
    al.add(str1);
    al.add(str2);

  • How to create PNG file from byte array of RGB value?

    Hi
    Here is my problem.
    I have drawn some sketchs (through code in runtime) on canvas. I have grabbed the RGB information for the drwan image and converted to byte array.
    I have to pass this byte array to server and generate a png file and save.
    Please help.

    {color:#ff0000}Cross posted{color}
    http://forum.java.sun.com/thread.jspa?threadID=5218093
    {color:#000080}Cross posting is rude.
    db{color}

  • How to design and implement an application that reads a string from the ...

    How to design and implement an application that reads a string from the user and prints it one character per line???

    This is so trivial that it barely deserves the words "design" or "application".
    You can use java.util.Scanner to get user input from the command line.
    You can use String.getChars to convert a String into an array of characters.
    You can use a loop to get all the characters individually.
    You can use System.out.println to print data on its own line.
    Good luck on your homework.

  • Create an image from Component

    I have created an ImageLoader that stores images loaded from the filesystem. I do however need a default image that is not reliant on loading an image from the filesystem, in case any images on the filesystem are not found.
    I have tried to use Components createImage() method, until I read that this can only be used if the Component is visible on screen, which my Component never will be.
    What I really want is a grey rectangle as an ImageIcon by what means I get this I'm not bothered,
    hopefully someone can help

    Use the java.awt.image.BufferedImage class. To create a BufferedImage object, no component need to be visible. Here is some sample code:       BufferedImage image = new BufferedImage(wid, ht, BufferedImage.TYPE_INT_RGB);
           Graphics2D gc = image.createGraphics();
           gc.drawRect(x,y, width, height);Note that BufferedImage is a subclass of Image. So, you can create ImageIcon from a BufferedImage object.
    If you don't want to use BufferedImage, an option would be to create the image from an array of bytes.

  • Method to create Player directly from the mp3 bytes array

    I was checking JMF and didn't find any method to play a mp3 informing its byte array
    Wouldn't it be an interesting method ? Ok, URL is much easier, but I am talking about ID3 files that has sequences of mp3 chuncks in the same file... Anyone knows a way to build a Player from mp3' array of bytes ???

    sergio_abreu wrote:
    Err, Sorry but I desagree.I expected as much
    It seems you didn't understand my question well.Quite possibly
    I think the form I wrote was confusing:
    In +"Anyone knows a way to build a Player from mp3' array of bytes ???+"
    I meant: Anyone knows a way to create a Player or MediaPlayer CLASS from DYNAMIC mp3' array of bytes ???That's even less coherent, to be honest
    Have you seen the structure of an ID3 music file (album) ? It's a collection of mp3 chuncks in only one file.ID3 is simply metadata about a work. It is not "chunks of MP3"
    I have already designed a ID3 class (I called "ID3Info" ) in Java that extracts/shows (dump) all the mp3 from the ID3 file.ID3 isn't a file format. Nor can you extract an MP3 from it
    The thing I would need now is to have some methods in Manager Class from which I could choose which bytes of a generic file I want to load as an mp3 song, that's all.This makes zero sense. Like saying "I need a kettle which will turn furniture into weather"
    It would be nice if there were 2 new different methods:
    1) Player createRealizedPlayer( byte[] songBytes, String fileExtension);
    Arguments: the song byte array and the extension, ex. "mp3"And what would this method do? Where does the byte[] come from? What is in the file, that you also need in order to play the song? How is this - assuming it's possible - easier, better, than just playing the file?
    2) Player createRealizedPlayer( java.net.URL genericFileURL, int beginPosition, int endPosition, String fileExtension);
    Arguments: the URL of a file containing varios mp3 chuncks and the begin / end of the bytes to be loaded as a song and a String to describe the type of file ("mp3" for example)See above
    PS: If you find it interesting, I am willing to contribute to enrich even more the Java Media framework. If you think my ideas are not valid, I just ask someone to send me the jmf source code so that I can alter some classes for my tests only.Why do you need JMF source code? I don't think this magical upside-down-ness is going to enhance anything, to be honest

Maybe you are looking for

  • ICloud Photo Library - Are my camera photos being compressed?

    When 'Optimize iPhone Storage' is selected, are the photos I take with the iPhone being compressed and the originals deleted locally after being uploaded, or is it just photos taken with an iPad which are then synced across other devices that are 'op

  • Re-downloading deleted songs? (with a twist)

    Hey all, So I got a new iPhone and downloaded the new iTunes (haven't used either in many years) and I figured 'what the heck ill figure it out.' So in my haste I started clicking the "cloud" icon next to most of my albums thinking I had to download

  • How to i m find my iphone country and service provide

    How to i m find my iphone country and service provider

  • How can I export the query result into access(*.mdb) file?

    Dear all: I want to export the query result displayed in jsp into excel file and access file. And I have exported the result into excel format successfully, only one line should be added in the head of Jsp: <%@ page contentType="application/vnd.ms-ex

  • Services panel Refresh command fails

    I'm unable to make the Refresh command work. I'm attempting to ue it withj BlazeDS, and is currently using version 4 of Blaze. I've used it both with Blaze direclty, as well as running Blaze under Spring. Same problem. I am able to establish the serv