How to recognize string in txt file and set it as variable

Hi, 
I have txt file and somwhere in it string starting with:
data directory....:
How (using batch file) find it in the text, read and set the value as a variable? I mean the string is:
data directory....: c:\datadir
where what I mean value is  in this case "c:\datadir". So I want batch file to read the txt file, find string starting with "data directory....:" and then set "c:\datadir" as a variable. 
Best, mac

It's not very intuitive to do this sort of thing in a batch file. If you have the option to use PowerShell instead, I'd highly recommend it. It's the new way for performing command-line tasks in Windows, and there's no need to struggle with the old command
prompt anymore.
Here are PowerShell and batch examples of doing this type of string parsing:
# PowerShell:
$dataDirectory = Get-Content .\test.txt |
ForEach-Object {
if ($_ -match '^\s*data directory\.*:\s*(.+?)\s*$')
$matches[1]
break
$dataDirectory
# Batch file:
@echo off
setlocal EnableDelayedExpansion
set DATA_DIRECTORY=
for /F "tokens=1,* delims=:" %%a in (test.txt) do (
set PROPERTY=%%a
set PROPERTY=!PROPERTY:~0,14!
if /I "!PROPERTY!" equ "data directory" (
set DATA_DIRECTORY=%%b
:RemovingSpaces
if "%DATA_DIRECTORY:~0,1%" neq " " goto :SpacesRemoved
set DATA_DIRECTORY=%DATA_DIRECTORY:~1%
goto :RemovingSpaces
:SpacesRemoved
echo %DATA_DIRECTORY%
endlocal

Similar Messages

  • How to search a special string in txt file and return it's position in txt file?

    How to search a special string in txt file and return it's position in txt file?

    I just posted a solution for a similar question here:  http://forums.ni.com/ni/board/message?board.id=170​&view=by_date_ascending&message.id=362699#M362699
    The top portion can search for the location of a string, while the bottom portion is to locate the position of a character.  Both can search for a character.
    The position of the character within the file is displayed in the indicator(s).
    R

  • How to add text in .ai file and  set position, font, size and colour

    I want to place multiple lines of of text (individually) into .ai file and set size, font, colour and position for each.
    Preferably text should have origin in a single point (rather than be framed)
    Hope anyone can help me out.
    Thank you in advance.

    Here's what's in the Scripting Reference
    Creating and modifying text frames
    // Creates a document with text frames displaying path, area and point
    // text, changes the content of each frame then deletes the 2nd frame
    // create a new document
    var docRef = documents.add();
    // create 3 new textFrames (area, line, point)
    // Area Text
    var rectRef = docRef.pathItems.rectangle(700, 50, 100, 100);
    var areaTextRef = docRef.textFrames.areaText(rectRef);
    areaTextRef.contents = "TextFrame #1";
    areaTextRef.selected = true;
    // Line Text
    var lineRef = docRef.pathItems.add();
    lineRef.setEntirePath( Array(Array(200, 700), Array(300, 550) ) );
    var pathTextRef = docRef.textFrames.pathText(lineRef);
    pathTextRef.contents = "TextFrame #2";
    pathTextRef.selected = true;
    // Point Text
    var pointTextRef = docRef.textFrames.add();
    pointTextRef.contents = "TextFrame #3";
    pointTextRef.top = 700;
    pointTextRef.left = 400;
    pointTextRef.selected = true;
    redraw();
    // count the TextFrames
    var iCount = docRef.textFrames.length;
    var sText = "There are " + iCount + " TextFrames.\r"
    sText += "Changing contents of each TextFrame.";
    // change the content of each
    docRef.textFrames[0].contents = "Area TextFrame.";
    docRef.textFrames[1].contents = "Path TextFrame.";
    docRef.textFrames[2].contents = "Point TextFrame.";
    redraw();
    docRef.textFrames[1].remove();
    redraw();
    // count again
    var iCount = docRef.textFrames.length;
    Your are looking stuff with the pointTextRef.

  • How can i read only .txt file and skip other files in Mail Sender Adapter ?

    Hi Friends ,
                       <b> I am working on scenario like , I have to read an mail attachement and send the data to R3.</b>
                        It is working fine if only the .txt file comes.
                      <b>Some times ,html files also coming along with that .txt files. That time my Mail adapter fails to read the .txt file.</b>
                       I am using PayLoadSwap Bean and MessageTransformBean to swap and send the attachment as payload .
                         <b>Michal as told to write the Adapter module to skip the files .But i am not ware of the adapter moduel . If any blogs is there for this kind of scenarios please give me the link.</b>
                           Otherwise , please tell me how to write adapter module for Mail  Sender Adapter?
                      How to download the following
                        newest patch of XI ADAPTER FRAMEWORK CORE 3.0
    from SAP Service Marketplace. Open the file with WinZip and extract the following
    SDAs:
    &#61589;&#61472;aii_af_lib.sda, aii_af_svc.sda
    &#61589;&#61472;aii_af_cpa_svc.sda
                        I have searche in servive market place .But i couldn't find that . Can you please provide me the link to download the above .
                      If any other suggestions other than this please let me know.
    Regards.,
    V.Rangarajan

    =P
    Dude, netiquette. Messages like "i need this now! Do it!" are really offensive and no one here is being payed to answer anyone's questions. We're here because we like to contribute to the community.
    Anyway, in your case, just perform some search on how you could filter the files that are attached to the message. The sample module is just an example, you'll have to implement your own. Tips would be to query the filename of the attachments (or maybe content type) and for the ones which are not text, remove them.
    Regards,
    Henrique.

  • How do I read a txt file and keep only IP addresses based on the first 2 or 3 octets of the IP?

    Hello,
    I have a text file and each line contains random text followed by an IP address as follows.
    some text....172.30.25.30
    some text.....172.30.85.10
    some text..172.30.25.35
    some text.......172.30.85.11
    some text....172.30.15.1
    some text...172.30.15.2
    some text.......172.10.1.1
    some text...172.20.4.2
    some text..172.10.1.2
    some text.....172.20.5.1
    I'd like to create an output file which has only one entry for each unique entry in the file where either the first 2 or 3 octets are unique as follows:
    Output File
    172.30.25
    172.30.85
    172.30.15
    172.10.1
    172.20
    Any suggestions are appreciated!
    Thanks for your help! SdeDot

    Thanks mjolinor.  Works great!
    Two questions.
    1. Could you plz suggest how this could be modified so this code would read the file in or accept it from the pipeline instead of wrapping the (@' around the data?
    2. Could you plz briefly describe some of the details of the code so I can further research and understand.
    Thanks for your help.
    Thanks for your help! SdeDot
    1. It already reads in the file.  The (@' .. '@) bits are just there to create a file using your test data to demonstrate that it works.
    2.  Not user what kind of "details" you want.  There really isn't much there, and get-help on the cmdlets used should provide information on what's going on with them in that script.
    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

  • How do I get back my files and setting after re-installing Lion?

    After I deleted the wrong file, I had to re-install Lion. After I went through the setup none of my file were on the desktop and the settings had all defaulted. After I looked under the User folder, I noticed there are 2 different users listed, ajoep3 and my_full_name.my_full_name contains all the files, and prseumably setting that I had before the re-install.
    How do I get those back? It won't allow me sign in under any other login.

    I have a backup, through Time Machine, but I didn't use that. I had files that weren't backed up on Time Machine, so I re-installed Lion from the App store. I hoped it would just replace the system files I had deleted. It's hard to explain, but the user names, ajoep3 and my_full_name are tied together.
    When I open the users folder it shows, ajoep with a house next to it, my_full_name and Shared. When I log in or out it only shows ajoep3. my_full_name isn't list in the system preferences>>users or any where else.

  • RandomAccessFile: How do I Clear the txt file and write multiple lines of..

    Hello all,
    I am a 6th grade teacher and am taking a not so "Advanced Java Programming" class. Could someone please help me with the following problem.
    I am having trouble with RandomAccessFile.
    What I want to do is:
    1. Write multiple lines of text to a file
    2. Be able to delete previous entries in the file
    3. It would also be nice to be able to go to a certian line of text but not manditory.
    import java.io.*;
    public class Logger
    RandomAccessFile raf;
    public Logger()
         try
              raf=new RandomAccessFile("default.txt","rw");
              raf.seek(0);
              raf.writeBytes("");
         catch(Exception e)
              e.printStackTrace();
    public Logger(String fileName)
         try
              raf=new RandomAccessFile(fileName,"rw");
              raf.seek(0);
              raf.writeBytes("");
         catch(Exception e)
              e.printStackTrace();
    public void writeLine(String line)
         try
              long index=0;
              raf.seek(raf.length());          
              raf.writeBytes(index+" "+line);
         catch(Exception e)
              e.printStackTrace();
    public void closeFile()
         try
              raf.close();
         catch(Exception e)
              e.printStackTrace();
         }

    Enjoy! The length of the code is highly attributable to the test harness/shell thingy at the end. But anyway seems to work nicely.
    import java.io.*;
    /** File structure is as follows. 1st four bytes (int) with number of live records. Followed by records.
    <p>Records are structured as follows<ul>
    <li>Alive or dead - int
    <li>Length of data - int
    <li>Data
    </ul>*/
    public class SequentialAccessStringFile{
      private static int ALIVE = 1;
      private static int DEAD = 0;
      private int numRecords, currentRecord;
      private RandomAccessFile raf;
      /** Creates a SequentialAccessStringFile from a previously created file. */
      public SequentialAccessStringFile(String filename)throws IOException{
        this(filename,false);
      /** Creates a SequentialAccessStringFile. If createnew is true then a new file is created or if it
          already exists the old one is blown away. You must call this constructor with true if you do
          not have an existing file. */
      public SequentialAccessStringFile(String filename, boolean createnew)throws IOException{
        this.raf = new RandomAccessFile(filename,"rw");
        if(createnew){
          truncate();
        this.currentRecord = 0;
        this.raf.seek(0);
        this.numRecords = raf.readInt();
      /** Truncates the file deleting all existing records. */
      public void truncate()throws IOException{
        this.numRecords = 0;
        this.currentRecord = 0;
        this.raf.setLength(0);
        this.raf.writeInt(this.numRecords);
      /** Adds the given String to the end of this file.*/
      public void addRecord(String toAdd)throws IOException{
        this.raf.seek(this.raf.length());//jump to end of file
        byte[] buff = toAdd.getBytes();// uses default encoding you may want to change this
        this.raf.writeInt(ALIVE);
        this.raf.writeInt(buff.length);
        this.raf.write(buff);
        numRecords++;
        this.raf.seek(0);
        this.raf.writeInt(this.numRecords);
        this.currentRecord = 0;   
      /** Returns the record at given index. Indexing starts at zero. */
      public String getRecord(int index)throws IOException{
        seekToRecord(index);
        int buffLength = this.raf.readInt();
        byte[] buff = new byte[buffLength];
        this.raf.readFully(buff);
        this.currentRecord++;
        return new String(buff); // again with the default charset
      /** Returns the number of records in this file. */
      public int recordCount(){
        return this.numRecords;
      /** Deletes the record at given index. This does not physically delete the file but simply marks the record as "dead" */
      public void deleteRecord(int index)throws IOException{
        seekToRecord(index);
        this.raf.seek(this.raf.getFilePointer()-4);
        this.raf.writeInt(DEAD);
        this.numRecords--;
        this.raf.seek(0);
        this.raf.writeInt(this.numRecords);
        this.currentRecord = 0;
      /** Removes dead space from file.*/
      public void optimizeFile()throws IOException{
        // excercise left for reader
      public void close()throws IOException{
        this.raf.close();
      /** Positions the file pointer just before the size attribute for the record we want to read*/
      private void seekToRecord(int index)throws IOException{
        if(index>=this.numRecords){
          throw new IOException("Record "+index+" out of range.");           
        if(index<this.currentRecord){
          this.raf.seek(4);
          currentRecord = 0;     
        int isAlive, toSkip;
        while(this.currentRecord<index){
          //skip a record
          isAlive = this.raf.readInt();
          toSkip = this.raf.readInt();
          this.raf.skipBytes(toSkip);
          if(isAlive==ALIVE){
               this.currentRecord++;
        // the next live record is the record we want
        isAlive = this.raf.readInt();
        while(isAlive==DEAD){
          toSkip = this.raf.readInt();
          this.raf.skipBytes(toSkip);
          isAlive = this.raf.readInt();     
      public static void main(String args[])throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Create a new file? y/n");
        System.out.println("(No assumes file exists)");
        System.out.print("> ");
        String command = br.readLine();
        SequentialAccessStringFile test = null;
        if(command.equalsIgnoreCase("y")){
          System.out.println("Name of file");
          System.out.print("> ");
          command = br.readLine();
          test = new SequentialAccessStringFile(command,true);     
        }else{
          System.out.println("Name of file");
          System.out.print("> ");
          command = br.readLine();
          test = new SequentialAccessStringFile(command);     
        System.out.println("File loaded. Type ? for help");
        boolean alive = true;
        while(alive){
          System.out.print("> ");
          command = br.readLine();
          boolean understood = false;
          String[] commandArgs = command.split("\\s");
          if(commandArgs.length<1){
               continue;
          if(commandArgs[0].equalsIgnoreCase("quit")){
               test.close();           
               alive = false;
               understood = true;           
          if(commandArgs[0].equalsIgnoreCase("list")){
               System.out.println("#\tValue");
               for(int i=0;i<test.recordCount();i++){
                 System.out.println(i+"\t"+test.getRecord(i));
               understood = true;
          if(commandArgs[0].equalsIgnoreCase("truncate")){
               test.truncate();
               understood = true;
               System.out.println("File truncated");
          if(commandArgs[0].equalsIgnoreCase("add")){
                test.addRecord(commandArgs[1]);
                understood = true;
                System.out.println("Record added");
          if(commandArgs[0].equalsIgnoreCase("delete")){
                int toDelete = Integer.parseInt(commandArgs[1]);
                if((toDelete<0)||(toDelete>=test.recordCount())){
                  System.out.println("Record "+toDelete+" does not exist");
                }else{
                  test.deleteRecord(toDelete);
                  System.out.println("Record deleted");
                understood = true;
          if(commandArgs[0].equals("?")){
               understood = true;
          if(!understood){
               System.out.println("'"+command+"' unrecognized");
               commandArgs[0] = "?";
          if(commandArgs[0].equals("?")){
               System.out.println("list - prints current file contents");
               System.out.println("add [data] - adds data to file");
               System.out.println("delete [record index] - deletes record from file");
               System.out.println("truncate - truncates file (deletes all record)");
               System.out.println("quit - quit this program");
               System.out.println("? - displays this help");
        System.out.println("Bye!");
    }Sample output with test program
    C:\>java SequentialAccessStringFile
    Create a new file? y/n
    (No assumes file exists)
    yName of file
    mystringsFile loaded. Type ? for help
    add appleRecord added
    add orangeRecord added
    add cherryRecord added
    add pineappleRecord added
    list#       Value
    0       apple
    1       orange
    2       cherry
    3       pineapple
    delete 5Record 5 does not exist
    delete 1Record deleted
    list#       Value
    0       apple
    1       cherry
    2       pineapple
    add kiwiRecord added
    list#       Value
    0       apple
    1       cherry
    2       pineapple
    3       kiwi
    quitBye

  • How to get string (specified by line and column) from txt file with labview

    Hi everyone
    How to get string (specified by line and column) from txt file with labview
    thx 
    Solved!
    Go to Solution.

    As far as I know, a text file has no columns.  Please be more specific.  Do you mean something like the 5th word on line 4, where words are separated by a space, and lines are separated by a newline character?  You could the Read from Spreadsheet String function and set the delimiter to a space.  This will produce a 2D array of strings.  Then use index array and give the line number and column number.
    - tbob
    Inventor of the WORM Global

  • How to encypt a .txt file and how to decrypt a same .txt file when i need

    My requirement is i want to encrypt a .txt file and
    keep it in some folder. In that file we put database connection
    information. when ever we need that file we have to access it and decrypt
    it. with that decrypted values we have make connection with database.
    i am sending a code in which i wrote both encyption and decrytion in same file, but i want to do it separately.
    Please help me regarding this.
    package com.businessobjects;
    import java.io.*;
    import java.security.*;
    import javax.crypto.*;
    public class EncryptDecrypt
         public static void EncodeIt()
              try
              // generate Cipher objects for encoding and decoding
              Cipher itsocipher1 = Cipher.getInstance("DES");
              Cipher itsocipher2 = Cipher.getInstance("DES");
              // generate a KeyGenerator object
              KeyGenerator KG = KeyGenerator.getInstance("DES");
              System.out.println("Using algorithm " + KG.getAlgorithm());
              // generate a DES key
              Key mykey = KG.generateKey();
              // initialize the Cipher objects
              System.out.println("Initializing ciphers...");
              itsocipher1.init(Cipher.ENCRYPT_MODE, mykey);
              itsocipher2.init(Cipher.DECRYPT_MODE, mykey);
              // creating the encrypting cipher stream
              //System.out.println("Creating the encrypting cipher stream...");
              /*FileInputStream fis = new FileInputStream("Original.txt");
    FileOutputStream fos = new FileOutputStream("Encypt.txt");
              CipherInputStream cis1 = new CipherInputStream(fis, itsocipher1);
              // creating the decrypting cipher stream
              //System.out.println("Creating the decrypting cipher stream...");
              byte[] b1 = new byte[8];
    int i1 = cis1.read(b1);
              while (i1 != -1)
                   fos.write(b1, 0, i1);
                   i1 = cis1.read(b1);
    fis.close();
    fos.close();*/
    // writing the decrypted data to output file
    FileInputStream fis1 = new FileInputStream("Encypt.txt");
    FileOutputStream fos1 = new FileOutputStream(Decypt.txt");
    CipherInputStream cis2 = new CipherInputStream(fis1, itsocipher2);
              byte[] b2 = new byte[8];
              int i2 = cis2.read(b2);
              while (i2 != -1)
                   fos1.write(b2, 0, i2);
                   i2 = cis2.read(b2);
    fis1.close();
              fos1.close();
    //cis1.close();
              cis2.close();
              catch (Exception e)
              System.out.println("Caught exception: " + e);
    With regards
    Pavankumar.

    here is the solution you wanted it
    uses password based encryption
    but your requirements are for very badly
    designed code
    This is the encryption part
    it converts the inputfile original.txt
    into the outputfile encrypt.txt which
    contains the original encrypted
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import javax.crypto.Cipher;
    import javax.crypto.spec.PBEKeySpec;
    import javax.crypto.spec.PBEParameterSpec;
    import javax.crypto.SecretKey;
    import javax.crypto.SecretKeyFactory;
    public class PWBEncryption {
        // Salt
        static byte[] salt = {
            (byte)0xc7, (byte)0x73, (byte)0x21, (byte)0x8c,
            (byte)0x7e, (byte)0xc8, (byte)0xee, (byte)0x99
        // Iteration count
        static int count = 20;
        public PWBEncryption() {
        // params:
        // password   -> the pasword used to create the key
        // inputfile  -> the file containing the stuff to be encrypted
        // i.e. original.txt
        // outputfile -> the file that will contain the encrypted stuff
        // i.e. encrypt.txt
        public static boolean doIt(char[] password,String inputfile,String outputfile){
            try{
                // Create PBE parameter set
                PBEParameterSpec pbeParamSpec = new PBEParameterSpec(salt, count);
                PBEKeySpec pbeKeySpec = new PBEKeySpec(password);
                // create secretkey
                SecretKeyFactory keyFac = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
                SecretKey pbeKey = keyFac.generateSecret(pbeKeySpec);
                // create cipher
                Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES");
                pbeCipher.init(Cipher.ENCRYPT_MODE, pbeKey, pbeParamSpec);
                // read input
                FileInputStream fis = new FileInputStream(inputfile);
                byte[] input = new byte[fis.available()];
                fis.read(input);
                // encrypt
                byte[] output = pbeCipher.doFinal(input);
                // write encrypted output
                FileOutputStream fos = new FileOutputStream(outputfile);
                fos.write(output);
                return true;
            catch(Exception e){
                System.out.println(e.toString());
                return false;
    }This is the decrypt part
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import javax.crypto.Cipher;
    import javax.crypto.spec.PBEKeySpec;
    import javax.crypto.spec.PBEParameterSpec;
    import javax.crypto.SecretKey;
    import javax.crypto.SecretKeyFactory;
    public class PWBDecryption {
        // Salt
        static byte[] salt = {
            (byte)0xc7, (byte)0x73, (byte)0x21, (byte)0x8c,
            (byte)0x7e, (byte)0xc8, (byte)0xee, (byte)0x99
        // Iteration count
        static int count = 20;
        public PWBDecryption() {
        // params:
        // password   -> the pasword used to create the key
        // inputfile  -> the file containing the decrypted data
        // i.e. encrypt.txt
        // outputfile -> the file that will contain the decrypted data
        // i.e. decrypt.txt
        public static boolean doIt(char[] password,String inputfile,String outputfile){
            try{
                // Create PBE parameter set
                PBEParameterSpec pbeParamSpec = new PBEParameterSpec(salt, count);
                PBEKeySpec pbeKeySpec = new PBEKeySpec(password);
                // create secretkey
                SecretKeyFactory keyFac = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
                SecretKey pbeKey = keyFac.generateSecret(pbeKeySpec);
                // create cipher
                Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES");
                pbeCipher.init(Cipher.DECRYPT_MODE, pbeKey, pbeParamSpec);
                // read input
                FileInputStream fis = new FileInputStream(inputfile);
                byte[] input = new byte[fis.available()];
                fis.read(input);
                // encrypt
                byte[] output = pbeCipher.doFinal(input);
                // write encrypted output
                FileOutputStream fos = new FileOutputStream(outputfile);
                fos.write(output);
                return true;
            catch(Exception e){
                return false;
    }runner
    public class RunRun {
        public RunRun() {
        public static void main(String args[]){
            char password[] = {'q','w','e','r','t','y'};       
            boolean enc = PWBEncryption.doIt(password,"C:\\original.txt","c:\\encrypt.txt");
            System.out.println("Encryption status == "+enc);
            boolean dec = PWBDecryption.doIt(password,"c:\\encrypt.txt","c:\\decrypt.txt");
            System.out.println("Decryption status == "+dec);
    }

  • I have dragged 2 files to the trash bin but I cannot delete them from the trash bin. It keeps telling me these files are in use when they are not. How do I delete these files? One is a txt file and the other is an xls file

    I have dragged 2 files to the trash bin but I cannot delete them from the trash bin. It keeps telling me these files are in use when they are not. How do I delete these files? One is a txt file and the other is an xls file

    From the Finder menu select 'Secure Empty Trash'. If this or the suggestion above doesn't resolve the problem take a look at the various suggestions in this link:
    http://www.thexlab.com/faqs/trash.html

  • How can i open a DOC or TXT file and insert the data into table?

    How can i open a DOC or TXT file and insert the data into table?
    I have a doc file . the doc include some columns and some rows.(for example 'ID,Name,Date,...').
    I'd like open DOC file and I'd like insert them into the table with same columns.
    Thanks.

    Use the SQL*Loader utility or the UTL_FILE package.

  • Every time I try to download the new version of Adobe Flash Player it saves as a .txt file and I do not know how to get it to save in the correct format.

    Every time I try to download the new version of Adobe Flash Player it saves as a .txt file and I do not know how to get it to save in the correct format.

    Please post in the Adobe Flash Player forum.

  • Reading .txt files and put it into a TextArea

    Hi all,
    I got a problem! I have to make something like a messenger.
    I want to put the written text into a .txt file, after that I have to get the text out of the .txt file and put in into a TextArea.
    I would ike it to to that like this:
    ">User 1
    Hello!
    >User 2
    Hi!
    Now here are my questions:
    1: What is the moet easy way to do this ?
    2: How could i put Enters into a .txt file with Java ?
    3: How could i read all the text from the .txt file and put it into a TextArea WITH ENTERS ?
    Thanks for your help!
    Greetings, Jasper Kouwenberg

    use JTextArea.read(new FileReader(fileName)) for reading.
    and JTextArea.write(new FileWriter(fileName)) for writing.
    The enters should be ok if the user press enter and adds a new line ("\n") to the text area component.
    It will save the enter in the text file and load it correctly back to the text area.
    If you want to add enter programmatically just add "\n" string to the text area component.

  • How to get Text from (.txt) file to display in the JTextArea ?

    How to get Text from (.txt) file to display in the JTextArea ?
    is there any code please tell me i am begginer and trying to get data from a text file to display in the JTextArea /... please help...

    public static void readText() {
      try {
        File testFile = new File(WorkingDirectory + "ctrlFile.txt");
        if (testFile.exists()){
          BufferedReader br = new BufferedReader(new FileReader("ctrlFile.txt"));
          String s = br.readLine();
          while (s != null)  {
            System.out.println(s);
            s = br.readLine();
          br.close();
      catch (IOException ex){ex.printStackTrace();}
    }rykk

  • I have a VI and an attched .txt data file. Now I want to read the data from the .txt file and display it as an array in the front panel. But the result is not right. Any help?

    I have a VI and an attched .txt data file. Now I want to read the data from the .txt file and display it as an array in the front panel. But the result is not right. Any help?
    Attachments:
    try2.txt ‏2 KB
    read_array.vi ‏21 KB

    The problem is in the delimiters in your text file. By default, Read From Spreadsheet File.vi expects a tab delimited file. You can specify a delimiter (like a space), but Read From Spreadsheet File.vi has a problem with repeated delimiters: if you specify a single space as a delimiter and Read From Spreadsheet File.vi finds two spaces back-to-back, it stops reading that line. Your file (as I got it from your earlier post) is delimited by 4 spaces.
    Here are some of your choices to fix your problem.
    1. Change the source file to a tab delimited file. Your VI will then run as is.
    2. Change the source file to be delimited by a single space (rather than 4), then wire a string constant containing one space to the delimiter input of Read From Spreadsheet File.vi.
    3. Wire a string constant containing 4 spaces to the delimiter input of Read From Spreadsheet File.vi. Then your text file will run as is.
    Depending on where your text file comes from (see more comments below), I'd vote for choice 1: a tab delimited text file. It's the most common text output of spreadsheet programs.
    Comments for choices 1 and 2: Where does the text file come from? Is it automatically generated or manually generated? Will it be generated multiple times or just once? If it's manually generated or generated just once, you can use any text editor to change 4 spaces to a tab or to a single space. Note: if you want to change it to a tab delimited file, you can't enter a tab directly into a box in the search & replace dialog of many programs like notepad, but you can do a cut and paste. Before you start your search and replace (just in the text window of the editor), press tab. A tab character will be entered. Press Shift-LeftArrow (not Backspace) to highlight the tab character. Press Ctrl-X to cut the tab character. Start your search and replace (Ctrl-H in notepad in Windows 2000). Click into the Find What box. Enter four spaces. Click into the Replace With box. Press Ctrl-V to paste the tab character. And another thing: older versions of notepad don't have search and replace. Use any editor or word processor that does.

Maybe you are looking for

  • Stuck in grayscale, can't access image mode rgb

    For some reason photoshop decided I didn't want to work in color on a certain image anymore, and isn't allowing me to access the usual fix for undoing grayscale. I've been pulling my hair out trying to recover this image and can't find a solution onl

  • Pop - gmail - mail no longer downloading after 10.5.8 update

    I don't know if it's related to the update - and I think I also updated safari (which I never use) but overnight my mail program has stopped downloading new mail from my Gmail account, which has always worked without a hitch. The connection doctor sa

  • Since i update ios5, iphone is not connected to my wifi

    since i update ios5, iphone is not connecting to my wifi,

  • Adding Blood Effect

    Im making a history movie and I have these quick time clips of explosions of blood hitting the camera. How could i combine this with the video that I have now?? Thanks Max

  • How can I modify the opacity of my toolbars?

    I am in process of setting up a new PC. I installed FF8 and imported my old bookmarks. The toolbars across the top are all opaque. This part of my desktop can be see (a little blurred) which make it very difficult to pick out toolbar buttons!