No installation. USB stick portable applications.
Swiss File Knife

a command line
multi function tool.

remove tabs
list dir sizes
find text
filter lines
find in path
collect text
instant ftp or
http server
file transfer
send text
patch text
patch binary
run own cmd
convert crlf
dup file find
md5 lists
fromto clip
hexdump
split files
list latest
compare dirs
save typing
trace http
echo colors
head & tail
find classes
dep. listing
speed shell
zip search
zip dir list

Depeche View
Source Research
First Steps

firefox add-ons

using vm linux

windows GUI
automation

the d3caster
java game engine

command line
file encryption

free external tools,
zero install effort,
usb stick compliant:

zip and unzip
diff and merge
reformat xml
reformat source

java sources

thread creation

cpp sources

log tracing
mem tracing
hexdump
using printf

articles

embedded
stat. c array
stat. java array
var. c array
var. java array
view all text
as you type
surf over text
find by click
quick copy
multi view
find nearby
fullscreen
bookmarks
find by path
expressions
location jump
skip accents
clip match
filter lines
edit text
highlight
load filter
hotkey list
receive text
send in C++
send in Java
smooth scroll
touch scroll
fly wxWidgets
fly over Qt
search Java

Arrays in Java: Java code example for using a variable sized array.

How to read a text file of any size into a variable sized, growing array, also allowing
text lines of differing length, demonstrating dynamic memory allocation.


 
/*
   Java array source code example:
   -  read text file into a variable sized array
   -  sort the array
   -  write array content into another text file.

   Put this text into a file tmp2.java.
*/

import java.io.*;

public class tmp2
{
   // static start point (no object yet)
   public static void main(String args[]) throws Throwable
      { new tmp2().main2(args); }

   // dynamic start point (on a single object)
   public int main2(String args[]) throws Throwable
   {
      if (args.length < 2)
         return 9+perr("supply in- and output filename.");

      String sInFile  = args[0];
      String sOutFile = args[1];

      // full flexible array for text storage:
      int iLinesAlloced  = 10;  // initial array size
      int iLinesUsed     =  0;  // number of lines actually used
      String aTextData[] = new String[iLinesAlloced+10];
      // +10 are safety spaces, to avoid crash on off-by-one errors.

      // read input file into the array.
      BufferedReader fin = new BufferedReader(
         new InputStreamReader(
             new FileInputStream(args[0]), "ISO-8859-1"
             // or US-ASCII,UTF-8,UTF-16BE,UTF-16LE,UTF-16
             ));

      while (true)
      {
         String sLine = fin.readLine();
         if (sLine == null)
            break; // end of file

         // space left in the array?
         if (iLinesUsed >= iLinesAlloced)
         {
            // no: expand the array
            int iNewSize = iLinesAlloced * 2 + 10;
            print("[expanding array to "+iNewSize+" lines]\n");
            String aNewData[] = new String[iNewSize+10];
            if (aNewData == null)
              { perr("out of memory\n"); break; }
            System.arraycopy(aTextData,0, aNewData,0, iLinesUsed);
            aTextData = aNewData;
            // old aTextData is freed implicitely.
            iLinesAlloced = iNewSize;
         }

         aTextData[iLinesUsed] = sLine;

         iLinesUsed++;
      }

      fin.close();

      // do some processing on the array contents
      processData(aTextData, iLinesUsed, iLinesAlloced);

      // write the whole array to output file.
      PrintWriter fout = new PrintWriter(
         new OutputStreamWriter(
             new FileOutputStream(args[1]), "ISO-8859-1"
             ));

      for (int iLine=0; iLine<iLinesUsed; iLine++)
      {
         fout.println(aTextData[iLine]);
      }

      fout.close();

      return 0;
   }

   // processing example: sort array text lines alphabetically
   // with the simplest possible sorting algorithm (bubblesort).
   int processData(String aText[], int iLinesUsed, int iLinesAlloced)
   {
      int iOuterIdx, iInnerIdx;

      for (iOuterIdx=0; iOuterIdx<iLinesUsed; iOuterIdx++)
      {
         for (iInnerIdx=iOuterIdx+1; iInnerIdx<iLinesUsed; iInnerIdx++)
         {
            String sLine1 = aText[iOuterIdx];
            String sLine2 = aText[iInnerIdx];

            if (sLine1.compareTo(sLine2) > 0)
            {
               // swap both lines
               aText[iOuterIdx] = sLine2;
               aText[iInnerIdx] = sLine1;
            }
         }
      }

      print("sorted "+iLinesUsed+" lines.\n");

      return 0;
   }

   // alternative processing example: sort using the Arrays class
   int processData2(String aText[], int iLinesUsed, int iLinesAlloced)
   {
      java.util.Arrays.sort(aText, 0, iLinesUsed);
      return 0;
   }

   static int perr(String s)
      { System.err.print("error: "+s); return 0; }

   static int print(String s)
      { System.out.print(s); return 0; }
};
// See also: Simple Java example for a fixed-size array .
 
Download the free Depeche View Lite Text Search Tool