Posts

Showing posts from June 28, 2010

How to convert String to color code in java code examples

 public static Color convertStringToColor(String colorString)     {         int k = Integer.parseInt(colorString, 16);         int j1 = k >> 16 & 0xff;         int i2 = k >> 8 & 0xff;         int l2 = k & 0xff;         return new Color(j1, i2, l2);     }

How to copy file using FileReader in java

public static void copyFile(String sourcePath, String destinationPath){                                   File inputFile = new File(sourcePath);              File outputFile = new File(destinationPath);               try {                 FileReader in = new FileReader(inputFile);                 FileWriter out = new FileWriter(outputFile);                   int c;                   while ((c = in.read()) != -1)                   out...

How to copy file using FromFile in Struts java

public String copyFile(FormFile formFile, String destinationFolder,             String outputFileName) throws IOException {         byte[] data = new byte[1000];                 InputStream input = formFile.getInputStream();         String filename = formFile.getFileName();         new File(destinationFolder).mkdirs();         File file = new File(destinationFolder, outputFileName);         FileOutputStream output = new FileOutputStream(file);         try {             try {                 while (true) {                  ...

How to Draw Color Picker applet Java code example

import java.awt.*; public class ColorPicker extends Panel {     public ColorPicker(String s, Color c)     {         b = new Button("...");         p = new Panel();         setLayout(null);         color = c;         l = new Label(s);         l.setBounds(0, 0, 100, 20);         b.setBounds(100, 0, 20, 20);         p.setBounds(120, 0, 40, 20);         add(l);         add(b);         add(p);         setSize(160, 20);     }     public ColorPicker(String s, Color c, int w)     {         this(s, c);         l.setBounds(0, 0, w, 20);    ...

How to read data byte by byte in java code examples

public  void readDataByteByByte( byte[] data,int contentLength,InputStream raw){         InputStream in = new BufferedInputStream(raw);         int offset = 0;         try{         int bytesRead = 0;         while (offset < contentLength) {           bytesRead = in.read(data, offset, data.length - offset);           if (bytesRead == -1)             break;           offset += bytesRead;         }         }catch (Exception e) {             e.printStackTrace();         }         finally{ ...

Recent Post

Recent Posts Widget