Saving an integer array into a .txt file

hii, im only a beginner in java, so this is the only code i've learned so far for saving array elements into a file
     public static void saveNames(String [] name) throws IOException
               FileWriter file = new FileWriter("Example\\names.txt");
               BufferedWriter out = new BufferedWriter(file);
               int i = 0;
               while (i < name.length)
                         if (name[i] != null)
                              out.write(name);
                              out.newLine();
                              i++;
               out.flush();
               out.close();
However, this is only used for string arrays; and i can't call the same method for an integer array (because it's not compatible with null)
I don't really understand this code either... since my teacher actually just gave us the code to use, and didn't really explain how it works
I have the same problem for my reading a file code as well --> it's only compatible with string
     public static String [] readNames (String [] name) throws IOException
          int x = 0;
          int counter = 0;
          String temp = "asdf";
          name = new String [100];
          FileReader file = new FileReader("Example\\names.txt");
          BufferedReader in = new BufferedReader(file);
          int i = 0;
          while (i < array.length && temp != null)                    // while the end of file is not reached
               temp = in.readLine();
               if (temp != null)
                    name[i] = temp;                    // saves temp into the array
               else
                    name[i] = "";
               i++;
          in.close();                                   // close the file
          return name;
Could someone suggest a way to save elements from an integer array to a file, and read integer elements of that file?
Or if it's possible, replace null with a similar variable (function?), that is suitable for the integer array (i can't use temp != 0 because some of my elements might be 0)
Thanks so much!!!!!

because it's not compatible with nullI think it should be okay to just remove the null condition check since there are no null elements in a primitive array when writing.
Use Integer.parseInt() [http://java.sun.com/javase/6/docs/api/java/lang/Integer.html] to convert the String into an Integer when you read it back and use Integer.toString() to be able to write it as a String.

Similar Messages

  • Only writing Integer pixel array to a .txt file,or showing in Frame

    Sir,
    I want to write integer values (range:0 to 255) to a .txt file .Actually after manipulating a .jpeg/.gif image I have gotten a 2D pixel array and a 1D pixel array that can be easily shown in console but I want to write this pixel array into a .txt file. Using of writeInt() is not working. Actually after using this faction the created file contain information which is non-alphanumeric /alphanumeric characters......
    following is error free the code: Plz. See only and only into the �class TestImage�and plz look after line marked by //�my_problem_to_be_resolved.�It is just few lines of code .I promise you will not be bothered.Plz��..
    import java.awt.*;
    import java.io.File;
    import java.io.FileWriter;
    import java.awt.image.*;
    import java.io.*;
    import java.util.*;
    import javax.imageio.*;
    import javax.imageio.stream.*;
    import java.awt.image.Raster;
    import java.awt.image.WritableRaster;
    class Image {
    protected int width,height;
    // 'samples' stores the image pixel values.
    protected int[][] samples;
    // Constructor: Reads the image from the
    // specified file name.
    public Image(String filename)
    throws Exception { read(filename); }
    // Returns the pixel width of the image.
    public int getWidth() { return width; }
    // Returns the pixel height of the image.
    public int getHeight() { return height; }
    // Reads the image from the specified file
    // name into the 'samples' array. Throws an
    // exception if the image is stored in an
    // unsupported file format (currently only
    // .GIF, .JPG, and .PNG are supported by Sun).
    public void read(String filename)
    throws Exception {
    // Extract the file name suffix.
    String ext = filename.substring
    (filename.indexOf('.')+1);
    // Create a file object for the file name.
    File fileImage = new File(filename);
    // Get a list of ImageReaders that claim
    // to be able to decode this image file
    // based on the file name suffix.
    Iterator imageReaders = ImageIO.
    getImageReadersBySuffix(ext);
    ImageReader imageReader;
    // Grab the first ImageReader in the list.
    if (imageReaders.hasNext())
    imageReader = (ImageReader)
    imageReaders.next();
    // If we get here we cannot decode the image.
    else throw new IIOException
    ("Unsupported image format");
    // Create a file input stream object to
    // read the image date.
    FileImageInputStream imageInputStream =
    new FileImageInputStream(fileImage);
    // Tell the ImageReader object to read data
    // from our file input stream object.
    imageReader.setInput(imageInputStream);
    // Get the width and height of the image.
    width = imageReader.getWidth(0);
    height = imageReader.getHeight(0);
    // Read the image from the file input stream,
    // and close the input stream when done.
    BufferedImage bufImage =
    imageReader.read(0);
    imageInputStream.close();
    // Get a raster object so we can extract the
    // pixel data from the BufferedImage.
    WritableRaster wRaster =
    bufImage.getRaster();
    // Create our 'samples' 2d-array.
    samples = new int[height][width];
    // Extract the image data into our 'samples'
    // array.
    for (int row = 0; row < height; row++)
    for (int col = 0; col < width; col++)
    samples[row][col] =
    wRaster.getSample(col,row,0);
    // Write the image stored in the 'samples'
    // array to the specified file. The file name
    // suffix should be a supported image file
    // format (currently either .JPG or .PNG).
    public void write(String filename)
    throws Exception {
    // Extract the file name suffix.
    String ext = filename.substring
    (filename.indexOf('.')+1);
    // Create a file object for the file name.
    File fileImage = new File(filename);
    // Get a list of ImageWriters that claim to
    // be able to encode images in the specified
    // image file format based on the file name
    // suffix.
    Iterator imageWriters = ImageIO.
    getImageWritersBySuffix(ext);
    ImageWriter imageWriter;
    // Grab the first ImageWriter in the list.
    if (imageWriters.hasNext())
    imageWriter = (ImageWriter)
    imageWriters.next();
    // If we get here we cannot encode the image.
    else throw new IIOException
    ("Unsupported image format");
    // Create a file output stream object to
    // write the image data.
    FileImageOutputStream imageOutputStream
    = new FileImageOutputStream
    (fileImage);
    // Tell the ImageWriter to use our file
    // output stream object.
    imageWriter.setOutput
    (imageOutputStream);
    // The ImageWriter.write() method expects a
    // BufferedImage. Convert our 'samples' array
    // into a BufferedImage.
    BufferedImage bufImage =
    createBufferedImage();
    // Encode the image to the output file.
    imageWriter.write(bufImage);
    imageOutputStream.close();
    // Draws the image stored in the 'samples'
    // array on the specified graphics context.
    public void draw(Graphics gc,int x,int y){
    BufferedImage bufImage =
    createBufferedImage();
    gc.drawImage(bufImage,x,y,null);
    // Converts the 'samples' array into a
    // BufferedImage object. Students do not have
    // to understand how this works.
    private BufferedImage
    createBufferedImage() {
    // Create a monochrome BufferedImage object.
    BufferedImage bufImage = new
    BufferedImage(width,height,
    BufferedImage.TYPE_BYTE_GRAY);
    // Create a WriteableRaster object so we can
    // put sample data into the BufferedImage
    // object's raster.
    WritableRaster wRaster =
    bufImage.getRaster();
    // Copy the 'samples' data into the
    // BufferedImage object's raster.
    for (int row = 0; row < height; row++)
    for (int col = 0; col < width; col++)
    wRaster.setSample
    (col,row,0,samples[row][col]);
    // Return the newly created BufferedImage.
    return bufImage;
    } // End of Class Image
    class TestImage {
    public static void main(String args[])
    throws Exception {
    // Create a frame to display the image.
    Frame frame = new Frame("Test Image");
    frame.setSize(1024,768);
    frame.setVisible(true);
    Graphics gc = frame.getGraphics();
    try {
    // Read the image from the file.
    Image img = new Image("C:/lilies.jpg");
    int height=img.getHeight();
    int width =img.getWidth();
    //�my_problem_to_be_resolved.�
         File image_object_arry=new File("C:/Image_array.txt");
         FileOutputStream image_object_arry_stream= new FileOutputStream(image_object_arry);
         DataOutputStream int_image_object_arry_stream=new DataOutputStream(image_object_arry_stream);
    //Conversion of two dimensional pixel arrry into one dimensional array
    int intPixels1[] = new int [height * width];
    int k = 0;
    for(int i = 0; i <= width; i++) {
    for(int j = 0; j <= height; j++) {
    intPixels1[k] = img.samples[i][j];
    int_image_object_arry_stream.writeInt((int) intPixels1[k]);
    // System.out.println(intPixels1[k]);
    k = k+1;
    import java.awt.*;
    import java.io.File;
    import java.io.FileWriter;
    import java.awt.image.*;
    import java.io.*;
    import java.util.*;
    import javax.imageio.*;
    import javax.imageio.stream.*;
    import java.awt.image.Raster;
    import java.awt.image.WritableRaster;
    class Image {
    protected int width,height;
    // 'samples' stores the image pixel values.
    protected int[][] samples;
    // Constructor: Reads the image from the
    // specified file name.
    public Image(String filename)
    throws Exception { read(filename); }
    // Returns the pixel width of the image.
    public int getWidth() { return width; }
    // Returns the pixel height of the image.
    public int getHeight() { return height; }
    // Reads the image from the specified file
    // name into the 'samples' array. Throws an
    // exception if the image is stored in an
    // unsupported file format (currently only
    // .GIF, .JPG, and .PNG are supported by Sun).
    public void read(String filename)
    throws Exception {
    // Extract the file name suffix.
    String ext = filename.substring
    (filename.indexOf('.')+1);
    // Create a file object for the file name.
    File fileImage = new File(filename);
    // Get a list of ImageReaders that claim
    // to be able to decode this image file
    // based on the file name suffix.
    Iterator imageReaders = ImageIO.
    getImageReadersBySuffix(ext);
    ImageReader imageReader;
    // Grab the first ImageReader in the list.
    if (imageReaders.hasNext())
    imageReader = (ImageReader)
    imageReaders.next();
    // If we get here we cannot decode the image.
    else throw new IIOException
    ("Unsupported image format");
    // Create a file input stream object to
    // read the image date.
    FileImageInputStream imageInputStream =
    new FileImageInputStream(fileImage);
    // Tell the ImageReader object to read data
    // from our file input stream object.
    imageReader.setInput(imageInputStream);
    // Get the width and height of the image.
    width = imageReader.getWidth(0);
    height = imageReader.getHeight(0);
    // Read the image from the file input stream,
    // and close the input stream when done.
    BufferedImage bufImage =
    imageReader.read(0);
    imageInputStream.close();
    // Get a raster object so we can extract the
    // pixel data from the BufferedImage.
    WritableRaster wRaster =
    bufImage.getRaster();
    // Create our 'samples' 2d-array.
    samples = new int[height][width];
    // Extract the image data into our 'samples'
    // array.
    for (int row = 0; row < height; row++)
    for (int col = 0; col < width; col++)
    samples[row][col] =
    wRaster.getSample(col,row,0);
    // Write the image stored in the 'samples'
    // array to the specified file. The file name
    // suffix should be a supported image file
    // format (currently either .JPG or .PNG).
    public void write(String filename)
    throws Exception {
    // Extract the file name suffix.
    String ext = filename.substring
    (filename.indexOf('.')+1);
    // Create a file object for the file name.
    File fileImage = new File(filename);
    // Get a list of ImageWriters that claim to
    // be able to encode images in the specified
    // image file format based on the file name
    // suffix.
    Iterator imageWriters = ImageIO.
    getImageWritersBySuffix(ext);
    ImageWriter imageWriter;
    // Grab the first ImageWriter in the list.
    if (imageWriters.hasNext())
    imageWriter = (ImageWriter)
    imageWriters.next();
    // If we get here we cannot encode the image.
    else throw new IIOException
    ("Unsupported image format");
    // Create a file output stream object to
    // write the image data.
    FileImageOutputStream imageOutputStream
    = new FileImageOutputStream
    (fileImage);
    // Tell the ImageWriter to use our file
    // output stream object.
    imageWriter.setOutput
    (imageOutputStream);
    // The ImageWriter.write() method expects a
    // BufferedImage. Convert our 'samples' array
    // into a BufferedImage.
    BufferedImage bufImage =
    createBufferedImage();
    // Encode the image to the output file.
    imageWriter.write(bufImage);
    imageOutputStream.close();
    // Draws the image stored in the 'samples'
    // array on the specified graphics context.
    public void draw(Graphics gc,int x,int y){
    BufferedImage bufImage =
    createBufferedImage();
    gc.drawImage(bufImage,x,y,null);
    // Converts the 'samples' array into a
    // BufferedImage object. Students do not have
    // to understand how this works.
    private BufferedImage
    createBufferedImage() {
    // Create a monochrome BufferedImage object.
    BufferedImage bufImage = new
    BufferedImage(width,height,
    BufferedImage.TYPE_BYTE_GRAY);
    // Create a WriteableRaster object so we can
    // put sample data into the BufferedImage
    // object's raster.
    WritableRaster wRaster =
    bufImage.getRaster();
    // Copy the 'samples' data into the
    // BufferedImage object's raster.
    for (int row = 0; row < height; row++)
    for (int col = 0; col < width; col++)
    wRaster.setSample
    (col,row,0,samples[row][col]);
    // Return the newly created BufferedImage.
    return bufImage;
    } // End of Class Image
    /*class TestImage {
    public static void main(String args[])
    throws Exception {
    // Create a frame to display the image.
    Frame frame = new Frame("Test Image");
    frame.setSize(1024,768);
    frame.setVisible(true);
    Graphics gc = frame.getGraphics();
    try {
    // Read the image from the file.
    Image img = new Image("C:/srk.jpg");
    // Display the image.
    img.draw(gc,10,40);
    // Flip the image upside down
    //img.flipX();
    // Display the flipped image.
    img.draw(gc,20+img.getWidth(),40);
    // Write the new image to a file
    img.write("HorseNew.jpg");
    } catch (Exception e) {
    System.out.println
    ("Exception in main() "+e.toString());
    class TestImage {
    public static void main(String args[])
    throws Exception {
    // Create a frame to display the image.
    Frame frame = new Frame("Test Image");
    frame.setSize(1024,768);
    frame.setVisible(true);
    Graphics gc = frame.getGraphics();
    try {
    // Read the image from the file.
    Image img = new Image("C:/lilies.jpg");
    int height=img.getHeight();
    int width =img.getWidth();
    File image_object_arry=new File("C:/Image_array.txt");
    FileOutputStream image_object_arry_stream=new FileOutputStream(image_object_arry);
         DataOutputStream int_image_object_arry_stream=new DataOutputStream(image_object_arry_stream);
    //Conversion of two dimensional pixel arrry into one dimensional array
    int intPixels1[] = new int [height * width];
    int k = 0;
    for(int i = 0; i <= width; i++) {
    for(int j = 0; j <= height; j++) {
    intPixels1[k] = img.samples[i][j];
    int_image_object_arry_stream.writeInt((int) intPixels1[k]);
    // System.out.println(intPixels1[k]);
    k = k+1;
    catch (Exception e) {
    System.out.println("Exception in main() "+e.toString());
    catch (Exception e) {
    System.out.println("Exception in main() "+e.toString());
    }

    My Friend, you need to put your code within CODE tags
    And I suspect if anyone would go through your code this way.
    Assuming your problem is to write pixel values to a file you may use this,
          try{
            // Create file
            FileWriter fstream = new FileWriter("out.txt");
            BufferedWriter out = new BufferedWriter(fstream);
            for(int i =0; pixels.length() ; i++)
              out.write(pixels[i]+"\t");
           //Close the output stream
           out.close();
           }catch (Exception e){//Catch exception if any
          System.err.println("Error: " + e.getMessage());
        }

  • How to write exception information into a txt file??

    i got a program which generate lots of exception information. its hard to see from the screen, is there any way to make the input into some txt file?
    when i use
    try
    }catch(Exception ex)
    // to do something here and make the output into a txt file?
    }

    depending upon the version of jdk being used one of the options will be to fetch the StackTraceElement array and writing each of the element using the standard file io operation
                StackTraceElement[] elements = ex.getStackTrace();
                int noOfElements = elements.length;
                for (int i=0; i<noOfElements;i++)
                      //fetch the stacktrace element and write to a file.
                }Thanks
    Rahul

  • How to read and write a string into a txt.file

    Hi, I am now using BEA Workshop for Weblogic Platform version10. I am using J2EE is my programming language. The problem I encounter is as the above title; how to read and write a string into a txt.file with a specific root directory? Do you have any sample codes to reference?
    I hope someone can answer my question as soon as possible
    Thank you very much.

    Accessing the file system directly from a web app is a bad idea for several reasons. See http://weblogs.java.net/blog/simongbrown/archive/2003/10/file_access_in.html for a great discussion of the topic.
    On Weblogic there seems to be two ways to access files. First, use a File T3 connector from the console. Second, use java.net.URL with the file: protocol. The T3File object has been deprecated and suggests:
    Deprecated in WebLogic Server 6.1. Use java.net.URL.openConnection() instead.
    Edited by: m0smith on Mar 12, 2008 5:18 PM

  • Write arrays into a text file in different columns at different times

    Hi,
              I have a problem write data into a text file. I want to write 4 1D arrays into a text file. The problem is that I need to write it at different time and in different column (in other word, not only append the arrays).
    Do you have an idea to solve my problem?
    Thank you

    A file is long a linear string of data (text). In order ro insert columns, you need to rewrite the entire file, because colums are interlaced over the entire lenght of the file.
    So:
    read file into 2D array
    insert columns using array operations
    write resulting 2D array to file again.
    (Only if your colums are guaranteed to be fixed width AND you know the final number of colums, you could write the missing columns as spaces and then overwrite later. Still, it will be painful and inefficient, because column data are not adjacent in the file.)
    LabVIEW Champion . Do more with less code and in less time .

  • Can I use Bridge to export image data into a .txt file?

    I have a folder of images and I would like to export the File Name, Resolution, Dimensions and Color Mode for each file into one text file. Can I use Bridge to export image data into a .txt file?

    Hello
    You may try the following AppleScript script. It will ask you to choose a root folder where to start searching for *.map files and then create a CSV file named "out.csv" on desktop which you may import to Excel.
    set f to (choose folder with prompt "Choose the root folder to start searching")'s POSIX path
    if f ends with "/" then set f to f's text 1 thru -2
    do shell script "/usr/bin/perl -CSDA -w <<'EOF' - " & f's quoted form & " > ~/Desktop/out.csv
    use strict;
    use open IN => ':crlf';
    chdir $ARGV[0] or die qq($!);
    local $/ = qq(\\0);
    my @ff = map {chomp; $_} qx(find . -type f -iname '*.map' -print0);
    local $/ = qq(\\n);
    #     CSV spec
    #     - record separator is CRLF
    #     - field separator is comma
    #     - every field is quoted
    #     - text encoding is UTF-8
    local $\\ = qq(\\015\\012);    # CRLF
    local $, = qq(,);            # COMMA
    # print column header row
    my @dd = ('column 1', 'column 2', 'column 3', 'column 4', 'column 5', 'column 6');
    print map { s/\"/\"\"/og; qq(\").$_.qq(\"); } @dd;
    # print data row per each file
    while (@ff) {
        my $f = shift @ff;    # file path
        if ( ! open(IN, '<', $f) ) {
            warn qq(Failed to open $f: $!);
            next;
        $f =~ s%^.*/%%og;    # file name
        @dd = ('', $f, '', '', '', '');
        while (<IN>) {
            chomp;
            $dd[0] = \"$2/$1/$3\" if m%Link Time\\s+=\\s+([0-9]{2})/([0-9]{2})/([0-9]{4})%o;
            ($dd[2] = $1) =~ s/ //g if m/([0-9 ]+)\\s+bytes of CODE\\s/o;
            ($dd[3] = $1) =~ s/ //g if m/([0-9 ]+)\\s+bytes of DATA\\s/o;
            ($dd[4] = $1) =~ s/ //g if m/([0-9 ]+)\\s+bytes of XDATA\\s/o;
            ($dd[5] = $1) =~ s/ //g if m/([0-9 ]+)\\s+bytes of FARCODE\\s/o;
            last unless grep { /^$/ } @dd;
        close IN;
        print map { s/\"/\"\"/og; qq(\").$_.qq(\"); } @dd;
    EOF
    Hope this may help,
    H

  • How to export from a mysql table into a txt file?

    I an trying to export the result of a select query into a txt file, and I used the command:
    SELECT * INTO OUTFILE "D:\OUTFILE.TXT" FROM USERS;
    It replies: access denied.
    Do I need some special privilege to do the operation? Or is there anything wrong with the command? Can anybody please help me?

    I tried the statement and it worked for me.
    SELECT * INTO OUTFILE "C:\OUTFILE.TXT" FROM `certificationtype`
    If I did it on the drive MySQL was installed on (C:) and the file ended up in the directory C:\mysql\data.
    SELECT * INTO OUTFILE "D:\OUTFILE.TXT" FROM `certificationtype`
    If I did it to drive D: it ended up in the root.
    Note the command will fail if the output file exists.
    Do you have rights to the root of d:?
    rykk

  • How to save the content of a JTextArea into a txt file?

    Hi, I want to save the content of a JTextArea into a txt file line by line. Here is part of my code(catch IOException part is omitted):
    String s = textArea.getText();
    File file = new File("file.txt");
    BufferedWriter bw = new BufferedWriter(new FileWriter(file));
    bw.write(s);
    bw.close();
    But I found in the file all is binary code instead of text, any people can help me?
    Thanks in advance

    I can see text in the file now, but the problem is
    when I write three lines in textarea, for example
    111
    222
    333
    then I open the txt file with notepad, it is
    111222333
    How to save them line by line? Use a PrintWriter. It lets you write lines (it's the same class as System.out).
    http://java.sun.com/j2se/1.4/docs/api/java/io/PrintWriter.html

  • Array to store .txt file data

    I have a .txt file containing lines like the following:
    1,50000.343,2000.745
    2,25645.856,4600,856
    3,24356.756,8766,345
    I'd like to store the strings as numbers and place them into an array, but I'm unsure how to do so.
    Any help would be appreciated

    The StreamTokenizer class will help you read the input, separating numbers from commas. Once you have the number as a String, the classes like Double and Integer have constructors that accept String arguments and do the hard work for you:
    // someString came from the file
    // you checked to see if it had a "." and it didn't, so
    // you know it's an integer
    Integer myInteger = new Integer( someString );
    int myInt = myInteger.getInt();

  • Help needed saving text members to TAB delimited txt file

    I have 7 text memebrs each containing several lines of text
    that were pulled in and sorted from a TAB delimited text file.
    What I'd like to know is, is there any way to convert those
    text members back into the TAB delimited format from which they
    came? I'd like to be able to pull in the data, let it be edited to
    some extent, then saved back out..... and I'm not too sure how to
    go about it.
    Example of txt file:
    ID_No Name Age
    1 Phil 26
    2 Sam 34
    3 Mary 21
    They're then sorted in to text files of ID_No, Name, and Age,
    with the lists of the relevent items in each.
    Like.....
    ID_No
    1
    2
    3
    Name
    Phil
    Sam
    Mary
    Age
    26
    34
    21
    Certain lines of these text members change, depending on what
    the user selects. I'd like to put these sections back in their
    original TAB delimited format, but with any changed data replacing
    the old, so next ime the app is opened the new data is pulled in
    from the txt file.
    I know I'm probably going about this the wrong way, but it's
    the only way I know so far lol
    Any ideas?

    global filex, idlst, namelst, agelst
    on readtabline (str)
    tmpstr = ""
    y = 1
    repeat with x = 1 to the number of chars in str do
    if str.char[x] = tab then
    case y of
    1 : idlst.add (tmpstr)
    2 : namelst.add (tmpstr)
    3 : agelst.add (tmpstr)
    end case
    tmpstr = ""
    y = y + 1
    else
    tmpstr = tmpstr & str.char[x]
    end if
    end repeat
    agelst.add (tmpstr)
    end
    on exitFrame me
    idlst = [] --set up some lists to hold that data we read in
    namelst = []
    agelst = []
    filex = new (xtra "fileio")
    filex.openfile ("t.txt", 1)
    indata = filex.readfile() -- read the data in
    filex.closefile()
    filex = void
    repeat with x = 1 to the number of lines in indata do
    readtabline(indata.line[x]) --seprate it into its diffrent
    elements
    end repeat
    -- you now have your data sorted in to three list of id, age
    and name
    -- so you would now do what ever editing you wanted to do
    --now to write it out to a new file
    filex = new (xtra "fileio")
    filex.createfile (the moviepath & "tout.txt")
    filex.openfile (the moviepath & "tout.txt", 2)
    repeat with x = 1 to idlst.count() do
    filex.writestring (idlst[x] & tab & namelst[x] &
    tab & agelst[x] & return)
    end repeat
    filex.closefile()
    end
    I tested this on your exact scenario and it worked a brezze
    hope it helps
    Regards
    David

  • Saving and Loading variables in a .txt file (Offline)

    I'm working a software we've done with Flash, but we'd want
    people to be able to save the variables they selected. We need them
    to be able to save the value of about 10 variables in a file on
    their desktop, and then be able to load that file again.
    Is it possible to do that without having to use php or stuff
    like that (that's why we want to make it an offline applications so
    we don't have to use php to be able to save files).
    I know Actionscript looks a lot like Javascript and with
    Javascript it's really easy to do, but all the saving functions are
    blocked in Flash for security reasons.
    If anyone knows how to do that, to simply save and load a
    .txt file, please let me know. If it would be possible also to
    change the .txt to whatever else it would be even better. The file
    can still be opened in Notepad but at least it looks a bit more
    professionnal to have our own extension. Again in Javascript or
    with a .bat file it's really easy to save variables to whatever
    type of file, even to non existing types, it simply creates a text
    file with an unknown ending.
    Thanks!

    I found a page that explains in a really easy way how to
    communicate with Javascript if the flash object is contained in an
    html page, but I couldn't find any page explaining how it works if
    it's not in an html page. On our side, before using the software
    we're creating we'll convert it to a .exe. How can we call a
    Javascript from that .exe since we can't incorporate the Javascript
    in the container since there isn't really a container... Is there a
    way to link to a Javascript (.js) that would be in the same folder
    as the .exe? Or would there be a way to incorporate the Javascript
    right into the .exe?
    Let me know if any of you have a solution for that.
    Thanks!
    http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=Liv eDocs_Parts&file=00000342.html#wp126566

  • How can I convert an array into a .wav file?

    I have an array of points that I need converted and written into a .wav file. Any help?

    Indeed there is!
    Look at the attached vi....that's about all there is to it!
    Good Luck..
    Eric
    Eric P. Nichols
    P.O. Box 56235
    North Pole, AK 99705
    Attachments:
    ARRAY_TO_WAVE.vi ‏17 KB

  • Saving a CSV report output as TXT file

    Hi,
    We are generating reports on the web using Intenet Explorer. The report is a CSV report, i.e. the data displayed is comma separated. After generating the report, we need to save it as TXT file.
    If the length of a line is long (let us say more than 80 chars) while saving it as TXT file, it is saving as 2 lines. If the length of a line is less, then it is saving in a single line.
    How can I avoid this 2 line problem?
    I am not facing this problem if I generate report with Netscape browser and save as TXT file.
    We are using Reports 6i.
    Thanks in Advance,
    Srinivas

    Hello,
    I had the same problem. And I think what I did to fix it is I made the mode=charcter, batch=yes, and background=yes. Hope this helps.
    Martin

  • Bytes array into a wav file

    hi every1, any1 can help plz, how to write bytes from an audio file (which is stored in an array) back into a wave file thanx

    Hi,
    it is something like this:
    byte[] myByteArray;          //your bytearray
    AudioFormat myAudioFormat;     //neccessary to interpret the bytes in the right manner
    long mySampleFrameLength;     //how long your audiodata is
    AudioInputStream ais = new AudioInputStream(new ByteArrayInputStream(myByteArray), myAudioFormat, mySampleFrameLength);
    AudioSystem.write(ais, AudioFileFormat.Type.WAVE, new File("myWaveFile.wav"));

  • How to write records from a resultset into a txt file ???

    Hi, I am a newbie in java servlet technology. Currently, I am having a problem regarding how to write all my records from within a resultset into a text file.
    First, I put all my records into a string variable and then append the string into a stringbuffer. After that, I create a bufferoutputstream and used the write method to write into a text file. Below are the code I used in my program.
    Connection connection = null;
    Statement statement = null;
    ResultSet resultset = null;
    // Connect to database
    connection = getConnection();
    StringBuffer str_buf = new StringBuffer();
    statement = connection.createStatement();
    resultset = statement.executeQuery("SELECT * FROM STUDENT");
    String data_row = "";
    str_buf.append("STUDENT_ID,NAME,PHONE,ADDRESS,RESULT");
    while (resultset.next()) {
       data_row = "\n";
       data_row += resultset.getLong("STUDENT_ID");
       data_row += ",\"" + resultset.getString("NAME").trim() + "\"";
       data_row += ",\"" + resultset.getString("PHONE").trim() + "\"";
       data_row += ",\"" + resultset.getString("ADDRESS").trim() + "\"";
       data_row += ",\"" + resultset.getString("RESULT").trim() + "\"";
       str_buf.append(data_row);
    BufferedOutputStream buf_out = null;
    // Create a folder and write all records into info.txt
    String fileName = "student/info.txt";
    buf_out = new BufferedOutputStream(new FileOutputStream(fileName));
    int str_len     = str_buf.length();
    for (int i = 0; i < str_len; i++) {
       buf_out.write(str_buf.charAt(i));
    }So. is this a proper way to write information into a text file ?
    The total records are around 150 000. Now, I get an exception which is "XServletError : System.lang.outofmemory". It happen if the total records are more than 60 000, within a while loop when I try to append a string into a stringbuffer.
    How should I deal with this kind of situation?
    Thanks in advanced and any advice is appreciated. Example is even better to improve understanding.
    Thanks

    Connection connection = null;
    Statement statement = null;
    ResultSet resultset = null;
    // Connect to database
    connection = getConnection();
    StringBuffer str_buf = new StringBuffer();
    String fileName = "student/info.txt";
    FileWriter fw = new FileWriter(fileName);
    statement = connection.createStatement();
    resultset = statement.executeQuery("SELECT * FROM
    STUDENT");
    String data_row = "";
    fw.write("STUDENT_ID,NAME,PHONE,ADDRESS,RESULT");
    while (resultset.next()) {
    data_row = "\n";
    data_row += resultset.getLong("STUDENT_ID");
    data_row += ",\"" + resultset.getString("NAME").trim()
    + "\"";
    data_row += ",\"" +
    resultset.getString("PHONE").trim() + "\"";
    data_row += ",\"" +
    resultset.getString("ADDRESS").trim() + "\"";
    data_row += ",\"" +
    resultset.getString("RESULT").trim() + "\"";
    fw.write(data_row);
    fw.close();

Maybe you are looking for