Splitting text file

I have the below clas for splitting text files, but I am getting an error. Could someone please help? Thanks
public void splitFile(String file) {
          try {
               BufferedReader in = new BufferedReader(new FileReader(file));
               final int numOutputFiles = constants.getNUM_PRINTERS();
               int loopCounter=0;
               Object currentOutputFile = null;
               String sourceFile = in.readLine();
               PrintWriter out0 = new PrintWriter(new FileOutputStream(constants.getPRINTER1_FILENAME()));
               PrintWriter out1 = new PrintWriter(new FileOutputStream(constants.getPRINTER2_FILENAME()));
               PrintWriter out2 = new PrintWriter(new FileOutputStream(constants.getPRINTER3_FILENAME()));
               PrintWriter [] fileHandles = {out0, out1, out2};
               while (sourceFile != null) {
                    loopCounter++;
                    if (loopCounter == numOutputFiles) {
                         loopCounter=1;
                    ERROR-->currentOutputFile = fileHandles[loopCounter-1].println(sourceFile); <--ERROR
                    //currentOutputFile.write(sourceFile);          
               out0.close();
               out1.close();
               out2.close();
          } catch (Exception ex) {
               logger.error(EXCEPTION_MESSAGE,"Error splitting file: "+ex.getMessage());
               ex.printStackTrace();
     }The error I get is on the line above in bold, "Type mismatch: cannot convert to void from Object" .
Thanks!!

also, how can I get the PrintWriter file names to be dynamic instead of declaring 3 of them like I have it now? Lets say I need 5 files now, but in the future, I may need 2 files. So the "out" variable would have the out1 and out2 only.

Similar Messages

  • AppleScript Split text file into multiple files

    I have large text files that I would like to break up into individual files. They are compilations of articles; I want to create a new file for each article, which begins with:
         Document # of #
    I don't think any other lines start with "Document" so that might be fine as a delimiter.
    Also, it would be great if the new files could be named "LAT_1", "LAT_2", etc.
    I found this thread:
    AppleScript separating one text file into many at Paragraph break
    I tried the second script by twtwtw and changed
    set parsingText to "Document"
    but got the following error:
    error "Can’t get item 2 of {\"LAT 1985-1990 local food copy.txt\"}." number -1728 from item 2 of {"LAT 1985-1990 local food copy.txt"}
    I also found this thread but it was too complicated for me to understand. Re: Split a large text file with many entries into separate files
    Can anyone help me modify the script? I've been looking at this as well as Unix commands to use in Terminal, but I'm just too much of a beginner.
    Any assistance is much appreciated!
    Trisha

    Hello
    Here's a modified version of the script in
    Split a large text file with many entries into separate files
    https://discussions.apple.com/thread/5641125?tstart=0
    This will split the given text by delimiter line in the form of "Document # of #" and save each chunk of text from one delimiter to the preceding line of the next delimiter in separate file named after LAT_0000.txt, where 0000 is sequential number starting at 0001.
    Note that any text before the first delimiter is ignored and not saved in output file. You may select multiple input files. Existing file in the destination folder is overwritten. Input text is assumed to be in UTF-8 and each line is termitated by U+000A LINE FEED.
    set ff to choose file with prompt "Choose input file(s)." with multiple selections allowed
    set d to choose folder with prompt "Choose destination folder."
    set args to ""
    repeat with a in {d} & ff
        set args to args & " " & a's POSIX path's quoted form
    end repeat
    do shell script "/usr/bin/perl -CSDA -w <<'EOF' - " & args & "
    use strict;
    sub usage () {
        printf STDERR \"Usage: %s output_directory file [file ...]\\n\", $0;
        exit 1;
    &usage() unless @ARGV > 1;
    my $outdir = shift @ARGV;
    unless ( -d $outdir ) {
        printf STDERR \"Not a directory: %s\\n\", $outdir;
        &usage();
    my $i = 0;
    my ($n, $n0, $t);
    while (<ARGV>) {
        if ( /^ \\s* Document \\s+ [0-9]+ \\s+ of \\s+ [0-9]+ .* $/ox ) {
            $n = sprintf('LAT_%04d.txt', ++$i);             # e.g., LAT_0001.txt
            if ( $n0 ) {
                open(OUT, '>', \"$outdir/$n0\") or die $!;  # overwrite
                print OUT $t;
                close OUT;
            ($n0, $t) = ($n, $_);
        else {
            $t .= $_;
    if ( $n0 ) {
        open(OUT, '>', \"$outdir/$n0\") or die $!;          # overwrite
        print OUT $t;
        close OUT;
    EOF"
    Hope this may help,
    H

  • Split text file in multiple files based on a string

    Hey all,
    I want to split a text file into multiple files. I already found some examples where there is a split based on a number of files.
    http://forum.java.sun.com/thread.jspa?forumID=256&threadID=260930
    But I want to make a split based on a string (word) that I find in the file.
    Anyone that can help me ?
    Regards,
    Atmoz

    This is my testing code like it is now. Maybe there is a bug in there which causes a memory leak or so.
    public class test {
         public static void main(String args[]) {
              File sSourceDir = new File("D:\\Test\\");
              File sDestinationDir = new File("D:\\Test\\");
              File[] files = sSourceDir.listFiles(new Filter());
              for (int i=0; i<files.length; i++) {
                   File file = files;
                   if (file.isFile()) {
                        System.out.println("Splitting file: "+files[i]);
                        splitFile(file,sDestinationDir);
                   else {
                        System.out.println("Not a file: "+files[i]);
         public static File splitFile(File fSourceFile, File sDestinationDir) {
              int counter = 1;
              File fDestinationFile=new File(sDestinationDir,"NEW_"+counter+"_"+fSourceFile.getName());
              fDestinationFile.delete();
              String sLineOfData=null;
              boolean firstfile = true;
              try {
                   BufferedReader DataFileReader = new BufferedReader(new FileReader(fSourceFile));
                   PrintWriter outputStream = new PrintWriter(new FileWriter(fDestinationFile));
                   while ((sLineOfData = DataFileReader.readLine()) != null){
                        System.out.println(sLineOfData);
                        if (sLineOfData.indexOf("UNA:+") != -1) {
                             if (!firstfile) {
                                  counter++;
                                  fDestinationFile=new File(sDestinationDir,"NEW_"+counter+"_"+fSourceFile.getName());
                                  outputStream.close();
                                  outputStream = new PrintWriter(new FileWriter(fDestinationFile));
                                  outputStream.println(sLineOfData);     
                             else {
                                  firstfile = false;
                                  outputStream.println(sLineOfData);     
                        else {
                             outputStream.println(sLineOfData);
                   outputStream.close();
                   DataFileReader.close();
              } catch (FileNotFoundException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
              } catch (IOException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
              return fSourceFile;
    And this is an example of a file:
    PS: I cut out each long line (that line from 4000 chars)
    UNA:+,? '
    UNB+UNOC:3d+5499757493404:14+3014331700208:14+050114:1200+ACC302++STS.GZ++1++1'
    UNH+I15185477+UTILTS:D:03B:UN:E5BE03'BGM+E32::260+I15185477+9+NA'
    DTM+137:200501141151:203'DTM+735:?+0100:406'MKS+23'NAD+MR+3014331700208::9'
    UNA:+,? '
    UNB+UNOC:3+549975f7493404:14+3014331700208:14+050114:1200+ACC302++STS.GZ++1++1'
    UNH+I15185477+UTILTS:D:03B:UN:E5BE03'BGM+E32::260+I15185477+9+NA'
    DTM+137:200501141151:203'DTM+735:?+0100:406'MKS+23'NAD+MR+3014331700208::9'
    DTM+137:200501141151:203'DTM+735:?+0100:406'MKS+23'NAD+MR+3014331700208::8'
    UNA:+,? '
    UNB+UNOC:3g+5499757g493404:14+3014331700208:14+050114:1200+ACC302++STS.GZ++1++1'
    UNH+I15185477+UTILTS:D:03B:UN:E5BE03'BGM+E32::260+I15185477+9+NA'
    DTM+137:200501141151:203'DTM+735:?+0100:406'MKS+23'NAD+MR+3014331700208::9'Message was edited by:
    Atmozzz

  • How do I split text files and save them as different records

    Hi,
    I am trying to load files now from INBOX of a mail system
    directly into the database.
    We are collecting the news stories which get emailed to us.
    The Inbox file is a huge file with some kind of delimiter.
    How can I break at the delimiter and make the messages
    seperate using any of ORACLE tools.
    we have
    orcl 805
    forms/reports 5.0
    orcl express
    discoverer
    Please let me know if we have to use PEARL/C to accomplish this.
    or the UTL_FILE package in PL/SQL CAN HELP .
    thank you very much for your attention
    Arvin
    null

    hi arvin,
    i hope u would have tried out with sql * loader. If not, just try
    it out, i feel ur motive could be achieved with the loader .
    U need to prepare a control file with the loader options like
    insert, or replace, or append ... and the delimiter ur using and
    the table specs. u can find the syntax of loader statement by
    typing sqlldr from ur unix prompt.
    Arvin (guest) wrote:
    : Hi,
    : I am trying to load files now from INBOX of a mail system
    : directly into the database.
    : We are collecting the news stories which get emailed to us.
    : The Inbox file is a huge file with some kind of delimiter.
    : How can I break at the delimiter and make the messages
    : seperate using any of ORACLE tools.
    : we have
    : orcl 805
    : forms/reports 5.0
    : orcl express
    : discoverer
    : Please let me know if we have to use PEARL/C to accomplish
    this.
    : or the UTL_FILE package in PL/SQL CAN HELP .
    : thank you very much for your attention
    : Arvin
    null

  • How to adjust splitted lines into one line in Text file?

    Hi Guys,
    I have a text file with 3 fields(comma separated): GLCode (Number), Desc1 (Char), Desc2(Char) and need to load it into BW.
    My Text file looks like:
    1011.00,"Mejor PC Infrastructure","This line is ok."
    1012.00,"Telephone Equipment $","This line ends in next line.   
    1)Need to change the equipment immediately.
    2)Take immediate action"
    1013.00,"V1 Computer Server Infrastructure # Equip","For purchases
    of components that make up the company's network, such as servers, hubs, routers etc."
    1014.00,"Flash Drive","Need to provide all IT Developer"
    This is how file looks like. Now I need the followings:
    1. Need to remove the space and need to adjust the splitted line into one. Say here
    line/record 2 is splitted into 3 lines and need to adjust in 1 line.
    2. In Line 5 (Record 3) data splitted into 2 lines and need to make 1 line.
    3. Need to remove bad characters.
    Could someone help me please how to proceed ?
    Regards,

    Not quite correct by my testing.  Try:
    $i=0
    Get-Content .\test.txt | ForEach {
    If ($i%2){
    ("$Keep $($_)").Trim()
    }Else{
    $keep=$_
    }$i++
    Good catch!
    Boe Prox
    Blog |
    Twitter
    PoshWSUS |
    PoshPAIG | PoshChat |
    PoshEventUI
    PowerShell Deep Dives Book

  • How do i split content from the text file using tab and spaces...?

    Hi.. Just want to ask help to all the experts. Im new in java and i have this problem on how to split the contents of the text file. ill show you the contents in order to let you see what i mean.
    FileName: COL.txt
    AcctNo AcctName Primary Secondary Status Opendate
    121244 IPI Company Noel Jose Active 12/05/2007
    As you can see the content i want to split it per column.. Please help me

    Jose_Noel wrote:
    Hi prometheuzz,
    What do you mean by one thread...?You created two threads* with the same question in it. That way, people might end up giving you an answer that has already been posted in your other thread: thus wasting that person's time.
    Just don't create multiple threads with the same question please.
    * a thread is a post here at the forum

  • Splitting text form file

    Hello,
    This is the problem, I have a text file with mobile messages, here's an example of these messages.
    25 100
    SEND 2228161 Hello Pete
    RECEIVE 2228161 Hello Chris, how are you?
    SEND 2227765 I hate text speak
    RECEIVE 2228876 wot u on bout
    SEND 2227975 The quick brown fox jumped over the lazy dog
    SEND 2328161 Simple Simon met a pieman going to the fair
    SEND 2226543 Mary had a little lamb, its fleece was white as snow
    SEND 2226543 And everywhere that Mary went the lamb was sure to go
    I have to read the text file, for which the code I have succeeded in doing, the first line of the text file are integers, which I have to assign to to variables say sizeOfMessage and limitOfBox. The code I've written so far reconizes the SEND and RECEIVE messages, using if (line.startsWith("SEND")), this I've tested it works. Now here is where I am pulling my hair out, I need to read the line, evaluate the size of the message excluding the SEND and telephone number, if it is greater than the sizeOfMessage value, split the the message up, then store the fragmented message including the SEND and telephone message into an array. Here is the code so far:-
    tokens = new StringTokenizer(line, "");
                    while (tokens.hasMoreTokens())
                        //get next token
                         System.out.println(tokens.nextToken());
                        // split on the white space with eiher RECEIVE or SEND before it
                        String[] storeTokens = line.split("(SEND|RECEIVE)\\s");
                        if (line.startsWith("SEND"))
                            System.out.println("SEND message");
                            if ((storeTokens[1].length()) > 25)
                                String[] tempTokens = line.split("(?<=SEND)\\s");
                       }         How do I achieve this?
    Any help would be appreciated
    Thanks

    Here's a quick example. Hope this helps.
    /** testfile.txt **********************************
    25 100
    SEND 2228161 Hello Pete
    RECEIVE 2228161 Hello Chris, how are you?
    SEND 2227765 I hate text speak
    RECEIVE 2228876 wot u on bout
    SEND 2227975 The quick brown fox jumped over the lazy dog
    SEND 2328161 Simple Simon met a pieman going to the fair
    SEND 2226543 Mary had a little lamb, its fleece was white as snow
    SEND 2226543 And everywhere that Mary went the lamb was sure to go
    SEND 2226543 There was a labyrinth in the forest where the lamb was lost
    import java.util.*;
    import java.util.regex.*;
    import java.io.*;
    public class MindGames{
      int sizeOfMessage, limitOfBox;
      ArrayList<String> inputLines;
      ArrayList<ArrayList<String>> messages;
      public MindGames(String infilename){
        String line = null;
        inputLines = new ArrayList<String>();
        messages = new ArrayList<ArrayList<String>>();
        try{
          BufferedReader br = new BufferedReader(new FileReader(infilename));
          while ((line = br.readLine()) != null){
            inputLines.add(line);
        catch (Exception e){
          e.printStackTrace();
        String[] temp = (inputLines.remove(0)).split("\\s+"); //remove first line
        sizeOfMessage = Integer.parseInt(temp[0]);
        limitOfBox = Integer.parseInt(temp[0]);
        inputLines = gather(inputLines);
      public void reformatLines(){
        ArrayList<String> aline;
        for (String s : inputLines){
          String[] elements = s.split("\\s+", 3);
          aline = new ArrayList<String>();
          String[] folded = makeFold(elements);
          for (String m : folded){
            aline.add(m);
          messages.add(aline);
      /* gather msgs for same number */
      ArrayList<String> gather(ArrayList<String> lines){
        ArrayList<String> retval = new ArrayList<String>();
        int i = 0;
        String[] current, next;
        String[] dummy = {"", "", ""};
        while (i < lines.size()){
          current = lines.get(i++).split("\\s+", 3);
          if (i < lines.size()){
            next = lines.get(i++).split("\\s+", 3);
          else{
            next = dummy;
          while (next[1].equals(current[1]) && next[0].equals(current[0])){
            current[2] = current[2] + " " + next[2];
            if (i < lines.size()){
              next = lines.get(i++).split("\\s+", 3);
            else{
              next = dummy;
          retval.add(current[0] + " " + current[1] + " " + current[2]);
          if (! next.equals(dummy)){
            --i;
        return retval;
      /* the regex for this version honors word boundary and spaces btw them */
      String[] makeFold(String[] rawSplit){
        ArrayList<String> foldedMsg = new ArrayList<String>();
        String msg = rawSplit[2];
        // short msg | can fold at word boundary | extraordinary long word
        String regex
          = "^.{0," + sizeOfMessage + "}$|.{1," + sizeOfMessage
          + "}(?=\\s|$)|[^\\s]{1," + sizeOfMessage + "}";
        String s;
        Pattern pat = Pattern.compile(regex);
        Matcher mat = pat.matcher(msg);
        while (mat.find()){
          s = mat.group();
          foldedMsg.add(rawSplit[0] + " " + rawSplit[1] + " " + s);
        return foldedMsg.toArray(new String[1]);
      public void testOutput(){
        for (ArrayList<String> as : messages){
          for (String str : as){
            System.out.println(str);
      public static void main(String[] args){
        MindGames mg = new MindGames("testfile.txt");
        mg.reformatLines();
        mg.testOutput();
    /*** output for inputting testfile.txt ***************
    SEND 2228161 Hello Pete
    RECEIVE 2228161 Hello Chris, how are you?
    SEND 2227765 I hate text speak
    RECEIVE 2228876 wot u on bout
    SEND 2227975 The quick brown fox
    SEND 2227975  jumped over the lazy dog
    SEND 2328161 Simple Simon met a pieman
    SEND 2328161  going to the fair
    SEND 2226543 Mary had a little lamb,
    SEND 2226543  its fleece was white as
    SEND 2226543  snow And everywhere that
    SEND 2226543  Mary went the lamb was
    SEND 2226543  sure to go There was a
    SEND 2226543  labyrinth in the forest
    SEND 2226543  where the lamb was lost
    *********************************************************/

  • Reading a text file line by line and splitting each line into an array

    I have a text file that I want to read in line by line and within each line, I want to do some processing. I have a file like the following:
    apples||oranges||bananas||grapes
    cars||trucks||planes||boats
    And I want to end up with an array such that
    First...
    item(0) = apples
    item(1) = oranges
    item(2) = bananas
    item(3) = grapes
    Then move onto the next line with item getting cleared each time. Can anyone offer any ideas on how do to this? I am unclear on reading line by line and then also splitting into an array as I am new to this.
    Thanks.

    For reading a text file in line by line, you want to use a FileReader (java.io.FileReader)
    If you wrap it in a Buffered reader, you can call readLine() and get the file one line at a time.
      File file = new File("C:\myFile.txt");
      BufferedReader in = new BufferedReader(new FileReader(file));
      String s = in.readLine();
      while (s != null){
        // string handling here
        s = in.readLine();
      }For the second part, you probably want to look at the method String.split() which should split your string up into an array for you. Check out the API for java.lang.String
    Check out the

  • File adapter-How to set line break in text file-split record into two lines

    Dear Guru's,
    I have to solve following problem with XML (with mulitiple records) to TEXT file scenario using file adapter. I have to output for ever ONE data record in XML always two identical lines in text file. Second line should have a little bit different mapping in few fields like date,... So I did duplicate fileds in my output structure in mapping and need to know how to set line break in the middle and see half of structure in first line and next structure half in second line
    My output structure in mapping is:
    CASHFLOW
    - INTERFACE
    - GESELLSCHAFT
    - ANWENDUNG
    - PRODUKT
    - VERTRAG
    - BETRAG
    - WAEHRUNG
    - DIRECTION
    - BEWEGUNGSTYP
    - FAELLIGKEIT
    - ZINSFESTSTELLUNG
    - ZAHLUNGSTAG
    - RENDITE
    - INTERFACE2
    - GESELLSCHAFT2
    - ANWENDUNG2
    - PRODUKT2
    - VERTRAG2
    - BETRAG2
    - WAEHRUNG2
    - DIRECTION2
    - BEWEGUNGSTYP2
    - FAELLIGKEIT2
    - ZINSFESTSTELLUNG2
    - ZAHLUNGSTAG2
    - RENDITE2
    Question is how can I set on receiving file adapter in Content Conversion Parameters that fields from first structure half INTERFACE...RENDITE should be outputed in one line and fields from second half of structure INTERFACE2...RENDITE2 should start on second line in final text file.
    I'm getting at the moment one line only and I need to know how can set line break so that second line starting with INTERFACE2(CA)...RENDITE2 will start in new line.
    CA,"0100","7","512",20090127010001,-12454762586.6800,"EUR",2,12,2009-01-28,2009-01-27,2009-01-28,"0.0000000",CA,"0100","7","512",20090127010001,-12454762586.6800,"EUR",1,10,2009-01-27,2009-01-27,2009-01-27,"0.0000000"
    This should be final output:
    CA,"0100","7","512",20090127010001,-12454762586.6800,"EUR",2,12,2009-01-28,2009-01-27,2009-01-28,"0.0000000"
    CA,"0100","7","512",20090127010001,-12454762586.6800,"EUR",1,10,2009-01-27,2009-01-27,2009-01-27,"0.0000000"
    My file adapter settings:
    RecordsetStructure=CASHFLOW
    CASHFLOW.fieldNames=INTERFACE,GESELLSCHAFT,ANWENDUNG,PRODUKT,VERTRAG,BETRAG,WAEHRUNG,DIRECTION,BEWEGUNGSTYP,FAELLIGKEIT,ZINSFESTSTELLUNG,ZAHLUNGSTAG,RENDITE
    CASHFLOW.fieldSeparator=,
    CASHFLOW.endSeparator='nl'
    CASHFLOW.fieldNames=INTERFACE2,GESELLSCHAFT2,ANWENDUNG2,PRODUKT2,VERTRAG2,BETRAG2,WAEHRUNG2,DIRECTION2,BEWEGUNGSTYP2,FAELLIGKEIT2,ZINSFESTSTELLUNG2,ZAHLUNGSTAG2,RENDITE2
    CASHFLOW.fieldSeparator=,
    It wont help if I add two identical structures in mapping because in output i would see for multiple entries section with first lines only and after that section with second lines only. And CASHFLOW is one part of more complex mapping ...
    (This is final output structure RecordsetStructure=HEADER,CASHFLOW,CONDITION,REFERENCE,CONTRACT - more sections with different data and all these should have duplicate lines at the end)
    Thanks a lot for any help
    Cheers
    Marian
    Edited by: Marian  Luscon on Jul 14, 2009 11:44 AM

    Hi Ivan,
    right, I did test just for sure.
    Putting constant 'nl' into field CASHFLOW-INTERFACE1 didnt help - still getting one line instead two lines.
    CA ,"0100" ,"7" ,"512" ,20090127GTP101 ,-12454762586.6800 ,"EUR" ,2 ,12 ,2009-01-28 ,2009-01-27 ,2009-01-28 ,"0.0000000" ,'nl' ,"GTP1" ,"7" ,"512" ,20090127GTP101 ,-12454762586.6800 ,"EUR" ,1 ,10 ,2009-01-27 ,2009-01-27 ,2009-01-27 ,"0.0000000"
    So there is still question. Is there any way (mapping,...) how to output always 2 lines in text file for one record in XML. It always does 1 record in mapping structure = 1 line but we need 2 lines ...
    Example:
    Input: 4 records in XML
    Output: 8 lines in final text file ...
    Thanks to you all guys
    Marian

  • Add/Remove Programs - export to text file?

    Hello,
    I am wondering if it is possible to export a list of everything in add/remove programs to a text file for inventory purposes.
    I have not found any easy method to do this short of copying reg files or installer 3rd party software.  Since the idea is to save time neither of those are viable solutions.
    Does anyone have any ideas?
    -Justin

    You could try this vbs script that lists installed programs and add info to a text file.
    Michael Petersen
    Option Explicit  
    Dim sTitle  
    sTitle = "InstalledPrograms.vbs by Bill James" 
    Dim StrComputer  
    strComputer = InputBox("Enter I.P. or name of computer to check for " & _  
                           "installed software (leave blank to check " & _  
                           "local system)." & vbcrlf & vbcrlf & "Remote " & _  
                           "checking only from NT type OS to NT type OS " & _  
                           "with same Admin level UID & PW", sTitle)  
    If IsEmpty(strComputer) Then WScript.Quit  
    strComputer = Trim(strComputer)  
    If strComputer = "" Then strComputer = "." 
    'Wscript.Echo GetAddRemove(strComputer)  
    Dim sCompName : sCompName = GetProbedID(StrComputer)  
    Dim sFileName  
    sFileName = sCompName & "_" & GetDTFileName() & "_Software.txt" 
    Dim s : s = GetAddRemove(strComputer)  
    If WriteFile(s, sFileName) Then 
      'optional prompt for display  
      If MsgBox("Finished processing.  Results saved to " & sFileName & _  
                vbcrlf & vbcrlf & "Do you want to view the results now?", _  
                4 + 32, sTitle) = 6 Then 
        WScript.CreateObject("WScript.Shell").Run sFileName, 9  
      End If 
    End If 
    Function GetAddRemove(sComp)  
      'Function credit to Torgeir Bakken  
      Dim cnt, oReg, sBaseKey, iRC, aSubKeys  
      Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE  
      Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _  
                  sComp & "/root/default:StdRegProv")  
      sBaseKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" 
      iRC = oReg.EnumKey(HKLM, sBaseKey, aSubKeys)  
      Dim sKey, sValue, sTmp, sVersion, sDateValue, sYr, sMth, sDay  
      For Each sKey In aSubKeys  
        iRC = oReg.GetStringValue(HKLM, sBaseKey & sKey, "DisplayName", sValue)  
        If iRC <> 0 Then 
          oReg.GetStringValue HKLM, sBaseKey & sKey, "QuietDisplayName", sValue  
        End If 
        If sValue <> "" Then 
          iRC = oReg.GetStringValue(HKLM, sBaseKey & sKey, _  
                                    "DisplayVersion", sVersion)  
          If sVersion <> "" Then 
            sValue = sValue & vbTab & "Ver: " & sVersion  
          Else 
            sValue = sValue & vbTab   
          End If 
          iRC = oReg.GetStringValue(HKLM, sBaseKey & sKey, _  
                                    "InstallDate", sDateValue)  
          If sDateValue <> "" Then 
            sYr =  Left(sDateValue, 4)  
            sMth = Mid(sDateValue, 5, 2)  
            sDay = Right(sDateValue, 2)  
            'some Registry entries have improper date format  
            On Error Resume Next   
            sDateValue = DateSerial(sYr, sMth, sDay)  
            On Error GoTo 0  
            If sdateValue <> "" Then 
              sValue = sValue & vbTab & "Installed: " & sDateValue  
            End If 
          End If 
          sTmp = sTmp & sValue & vbcrlf  
        cnt = cnt + 1  
        End If 
      Next 
      sTmp = BubbleSort(sTmp)  
      GetAddRemove = "INSTALLED SOFTWARE (" & cnt & ") - " & sCompName & _  
                     " - " & Now() & vbcrlf & vbcrlf & sTmp   
    End Function 
    Function BubbleSort(sTmp)  
      'cheapo bubble sort  
      Dim aTmp, i, j, temp  
      aTmp = Split(sTmp, vbcrlf)    
      For i = UBound(aTmp) - 1 To 0 Step -1  
        For j = 0 to i - 1  
          If LCase(aTmp(j)) > LCase(aTmp(j+1)) Then 
            temp = aTmp(j + 1)  
            aTmp(j + 1) = aTmp(j)  
            aTmp(j) = temp  
          End if  
        Next 
      Next 
      BubbleSort = Join(aTmp, vbcrlf)  
    End Function 
    Function GetProbedID(sComp)  
      Dim objWMIService, colItems, objItem  
      Set objWMIService = GetObject("winmgmts:\\" & sComp & "\root\cimv2")  
      Set colItems = objWMIService.ExecQuery("Select SystemName from " & _  
                                             "Win32_NetworkAdapter",,48)  
      For Each objItem in colItems  
        GetProbedID = objItem.SystemName  
      Next 
    End Function 
    Function GetDTFileName()  
      dim sNow, sMth, sDay, sYr, sHr, sMin, sSec  
      sNow = Now  
      sMth = Right("0" & Month(sNow), 2)  
      sDay = Right("0" & Day(sNow), 2)  
      sYr = Right("00" & Year(sNow), 4)  
      sHr = Right("0" & Hour(sNow), 2)  
      sMin = Right("0" & Minute(sNow), 2)  
      sSec = Right("0" & Second(sNow), 2)  
      GetDTFileName = sMth & sDay & sYr & "_" & sHr & sMin & sSec  
    End Function 
    Function WriteFile(sData, sFileName)  
      Dim fso, OutFile, bWrite  
      bWrite = True 
      Set fso = CreateObject("Scripting.FileSystemObject")  
      On Error Resume Next 
      Set OutFile = fso.OpenTextFile(sFileName, 2, True)  
      'Possibly need a prompt to close the file and one recursion attempt.  
      If Err = 70 Then 
        Wscript.Echo "Could not write to file " & sFileName & ", results " & _  
                     "not saved." & vbcrlf & vbcrlf & "This is probably " & _  
                     "because the file is already open." 
        bWrite = False 
      ElseIf Err Then 
        WScript.Echo err & vbcrlf & err.description  
        bWrite = False 
      End If 
      On Error GoTo 0  
      If bWrite Then 
        OutFile.WriteLine(sData)  
        OutFile.Close  
      End If 
      Set fso = Nothing 
      Set OutFile = Nothing 
      WriteFile = bWrite  
    End Function 
    Deploy deploy deploy

  • Java with Text file

    Hi
    I'm new in Java , just start 2 week agao, I want to read data for text file ...
    Argentina | Armenia | Australia | Austria | Azerbaijan |
    Canada | Cape Verde | Central African Republic | Chad | Chile | China |
    I will use " | " to separate a string and to parse this string to array.
    I have seen some the sample use : StringTokenizer but I didn't get about it
    can you give me more information or short code

    Sample code here: http://www.ccs.neu.edu/course/com3118/util2.html
    You could also use String.split()

  • Importing a text file into a variable

    I have a text file that I would like to import as a variable in javascript. I would like to do some editing to the text in the script before I place it into the page. I have the script splitting text into an array and the different parts need to go to different places... I have everything working for me except for importing the text from a file into a variable (right now I'm defining the variable from within the script).
    Any help would be appreciated!
    -Shane

    In Javascript you could use this:
    var f = File ('/d/books/mytextfile.txt');
    if (f.exists)
    f.open ('r', undefined, undefined);
    var textfile_contents = f.read();
    f.close ();
    Peter

  • Loading a text file into a global variable issue - really a global var?

    From all the documentation and examples I can find, it appears that it would be
    correct to create a global array variable [outside of any functions] to load image names into,
    then use these images for a slideshow. I want to make the app dynamic, in that changing the text file gives a new set of images.
    The global variable goes null [no values] after the load event listener. Why is that?
    Isn't global, well global, and alive for the duration of the SWF?
    PARAMS.TXT:
    monthNames=January,February,March,April,May,June,July,August,September,October,November,De cember&dayNames=Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday
    CODE:
    var dNames:Array = new Array();
    var mNames:Array = new Array();
    var request:URLRequest = new URLRequest("images/params.txt");
    var variables:URLLoader = new URLLoader();
    variables.dataFormat = URLLoaderDataFormat.VARIABLES;
    variables.addEventListener(Event.COMPLETE, completeHandler);
    try
    variables.load(request);
    catch (error:Error)
    trace("Unable to load URL: " + error);
    trace("2 mNames 2: " + mNames[2]);
    trace("2 dNames 3: " + dNames[3]);
    stop();
    function completeHandler(event:Event):void
    var loader:URLLoader = URLLoader(event.target);
    dNames = loader.data.dayNames.split(",");
    mNames = loader.data.monthNames.split(",");
    trace(loader.data.dayNames);
    trace("1 mNames 2: " + mNames[2]);
    trace("1 dNames 3: " + dNames[3]);
    OUTPUT:
    2 mNames 2: undefined
    2 dNames 3: undefined
    Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday
    1 mNames 2: March
    1 dNames 3: Wednesday
    How do I access these values after loading from the external file, after the load?
    Thanks in advance.

    The statement you quoted from whatever Adobe documentation is correct.
    If you want to load the data into the arrays before anything else happens, then have anything else that happens execute via the completeHandler function... after the data is loaded and processed into the arrays.
    the command: loadFile() executes before the trace("2:" +images[4]); command.  The loadFile function is processed and the loading process BEGINS... but starting the loading does not delay the main processing from continuing down the line--the loading itself becomes a secondary/background task.  The command was to execute the loadFile function and the processing of that function was completed.  If you don't believe so, then add a trace...
    function loadFile():void
         vars.dataFormat = URLLoaderDataFormat.VARIABLES;
         vars.addEventListener(Event.COMPLETE, onComplete, false, 0, true);
         vars.load(new URLRequest("images/fnames.txt"));
         trace("started loading");
    If you add that trace, you should see that the loadFile function execution is completed and the next line in your code is then processed... trace(2....)
    The addEventlistener does not stop anything.  The addEventListener code is assigning a monitor, not a traffic controller... it is telling the monitor to indicate when the data has finished loading.  It is not telling anything to stop program execution.
    So if you want to wait until the data is loaded before you do anything else... it goes....
    function onComplete(evt:Event):void
         var urlVars:URLVariables = evt.target.data;
         images = vars.data.images.split(",");
         tnails = vars.data.thumbnails.split(",");
         ................HERE.................

  • Problem in Using a Text file

    Hello,
    I want to read my text from a text file and it�s not a predetermined text, what i want to do is read the records in the form of text and i want to use "," as the delimiter between each Column in my Output file.
    I was trying to do this but somehow am not Achieving anything meaningful till now.
    Waiting for positive Reply�s from the Forum Memebers.

    The solution has already been suggested on this thread.
    http://forum.java.sun.com/thread.jspa?threadID=686118
    If you didn't get it, here are the steps again:
    1. Read the file using java io http://java.sun.com/docs/books/tutorial/essential/io/
    2. As you read each line, use StringTokenizer or String.split() to separate each value.
    You do not need to have a predetermined text. The only predetermined thing is your delimiter.
    x

  • Reading in an array from a text file

    I'm trying to use a text file to load in some configuratin
    data (using actionscript 3) I have it working ok for simple stuff
    like gamename=Chess&gamescore=100 , etc... but some of the data
    needs to be in an array. Can someone please point me in the right
    direction to how I can read in an array from a text file?
    Thanks!

    the easiest way is to create a string with the (soon-to-be)
    array elements separated by a delimiter (like a double comma). read
    in your string, then use the split() method of strings to split
    your string into an array.

Maybe you are looking for