Java File Read Sample Program

Program: import java.io.BufferedInputStream; import java.io.FileInputStream; import java.io.IOException; public class FileRead { public static void main(String[] args) throws IOException { int count =0; byte[] byte_value = new byte[1024]; FileInputStream fis = new FileInputStream("D:\\javadomain.txt"); BufferedInputStream bis = new BufferedInputStream(fis); while((count = bis.read(byte_value)) != -1){ String read = new String(byte_value,0,count); System.out.println(read); } } }   Output: D:\javadomain.txt file has the below content, Javadomain.in

71 total views, no views today

» Read more

Java File Writting example

Program: import java.io.File; import java.io.FileOutputStream; import java.io.IOException; public class FileWrite { public static void main(String[] args) { String input ="Javadomain.in can provides a programming problem solutions"; byte[] byte_input = input.getBytes(); try { FileOutputStream fos = new FileOutputStream(new File("D:\\javadomain.txt")); fos.write(byte_input); System.out.println("File created and input written in the file successfully"); } catch (IOException e) { e.printStackTrace(); } } }     Thanks

47 total views, no views today

» Read more

javascript onclick jsp value passing to servlet

Program: MyJsp.jsp <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Javadomain.in</title> </head> <script type="text/javascript"> function document123() { var append_input = document.getElementById("txt").value; document.location.href="/My_Workouts/MyServlet?nav=’"+append_input+"’"; // My_Workouts is the project name. } </script> <body> <label>Enter the text to pass Servlet </label> <input type="text" id="txt" ></input> <button type="button" onclick="document123()">Go to Servlet!</button></div> </body>

115 total views, 1 views today

» Read more

Javascript onclick Jsp call

Program: Input.jsp   <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Javadomain.in</title> </head> <body> <button type="button" onClick="JavaScript:window.location=’MyJsp.jsp’">Click to call MyJsp Page!</button> </body> </html>   MyJsp.jsp   <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Javadomain.in</title> </head>

93 total views, no views today

» Read more

Javascript trim function example

Javascript trim function program and the screenshot of the output is given below, Program: <!DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “http://www.w3.org/TR/html4/loose.dtd”> <html> <head> <meta http-equiv=”Content-Type” content=”text/html; charset=ISO-8859-1″> <title>Insert title here</title> </head> <body> <script type=”text/javascript”> function trim(withSpace) { return withSpace.replace(/^\s+|\s+$/g,””); } function getInput(){ var input = document.getElementById(“inp”).value; document.getElementById(“out”).value = trim(input); } </script> <form> Enter the input : <input type=”text” id=”inp”>

37 total views, no views today

» Read more