How to add strings to file?..
Hi, everybody!
Please, help me in a simple question:
I have to add strings to text-file.
ADD!
My task is:
if(the file isn't excist ){
create new file, open it and write, for example, 3 strings;
else{
open file and ADD 3 strings;
How to make it?
My text-file is big - nearly 65MB..
I'll be happy, if you can give example..
This file allows you to add to already available file, but if not available, it will be created.
Tell me if this helps you .
Cheers
* @Title :AddFile.java
* @date :today
* @version :v1.0
* @author :Your name
import java.io.*;
import java.net.*;
public class AddFile extends Object
public static void main (String [] args) throws IOException
System.out.print ("Enter your message: ");
BufferedReader input = new BufferedReader (
new InputStreamReader (System.in));
String userInput = input.readLine ();
BufferedWriter out = new BufferedWriter (
new FileWriter ("akoko.txt", true));
out.write (userInput);
out.close ();
}
Similar Messages
-
How to add an image file to Oracle db?
Need help urgently....Anybody knows how to add an image file (example: jpg)into one of the fields in Oracle database??
This will do the job..
package forum;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.sql.*;
import oracle.jdbc.driver.*;
//import oracle.sql.*;
Wanneer een request.getInputStream wordt geconferteerd naar een "String" (zie later) dan ziet de output in tekstformaat er als volgt uit:
-----------------------------7d280152604f4 Content-Disposition: form-data; name="oploadfile"; filename="C:\WINNT\Profiles\mvo\Desktop\boodschap.txt" Content-Type: text/plain Deze boodschap dient te worden ge-insert in de database. -----------------------------7d280152604f4 Content-Disposition: form-data; name="StadID" 1234 -----------------------------7d280152604f4 Content-Disposition: form-data; name="SuccessPage" /forum/error.jsp -----------------------------7d280152604f4--
of opgesplitst
contentType........... multipart/form-data; boundary=---------------------------7d235ade00f0
filename.............. "C:\Documents and Settings\Administrator\Desktop\boodschap.txt"
MIME type............. text/plain
Wat in database moet.. Dit is de eigenlijke boodschap die moet worden ge-insert in de database.
Eind boundary......... -----------------------------7d235ade00f0 Content-Disposition: form-data; name="file1"; filename="" Content-Type: application/octet-stream -----------------------------7d235ade00f0--
We gaan achtereenvolgens:
1. Kijken of het van het "multipart/form-data" type is (uploaden) en strippen van eerste boundery.
1.a Geen "multipart/form-data" ? dan... error message
1.b Groter dan MAX_SIZE ?..dan .. error message
2. Filenaam van de te uploaden file uitlezen
3. Mimetype bepalen en bepalen in welke positie van de string het Mimetype ophoudt, cq waar te uploaden file begint
4. Bepalen waar eind boundery begint
5. De eigenlijke file uitlezen
6. Terug converteren naar bytes
public class WriteBlob extends HttpServlet {
public static final int MAX_SIZE = ParameterSettings.imageUpload;
String successMessage = "";
public void init(ServletConfig config) throws ServletException {
super.init(config);
* Process the HTTP Get request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
DataInputStream in = null;
FileOutputStream fileOut= null;
PrintWriter out = response.getWriter();
int kb_size = 0;
boolean pass2 = true;
String message = "";
String responseRedirect = "/forum/uploaden.jsp?message="+" Uploaden geslaagd";
try
//get content type of client request
String contentType = request.getContentType();
// Start stap 1...content type is multipart/form-data
if(contentType != null && contentType.indexOf("multipart/form-data") != -1)
//open input stream
in = new DataInputStream(request.getInputStream());
//get length of content data
int formDataLength = request.getContentLength(); // totale lengte van de inputstream
//initieer een byte array om content data op te slaan
byte dataBytes[] = new byte[formDataLength];
//read file into byte array
int bytesRead = 0;
int totalBytesRead = 0;
int sizeCheck = 0;
while (totalBytesRead < formDataLength)
//kijken of de file niet te groot is
sizeCheck = totalBytesRead + in.available();
if (sizeCheck > MAX_SIZE)
pass2 = false;
message = "Sorry. U kunt slechts bestanden uploaden tot een grootte van 500KB";
responseRedirect = "/forum/uploaden.jsp?message="+message;
bytesRead = in.read(dataBytes, totalBytesRead,formDataLength);
totalBytesRead += bytesRead;
if (pass2==true)
kb_size = (int)(formDataLength/1024);
//create string from byte array for easy manipulation
String file = new String(dataBytes);
/*get boundary value (boundary is a unique string that separates content data)
contentType........... multipart/form-data; boundary=---------------------------7d235ade00f0
int lastIndex = contentType.lastIndexOf("=");
String boundary = contentType.substring(lastIndex+1, contentType.length());
// Stap 2.....bepaal de naam van de upload file
// filename.............. "C:\Documents and Settings\Administrator\Desktop\boodschap.txt"
String saveFile = file.substring(file.indexOf("filename=\"")+10);
saveFile = saveFile.substring(0,saveFile.indexOf("\n"));
saveFile = saveFile.substring(saveFile.lastIndexOf("\\")+1,saveFile.indexOf("\"")); //naam van de file...boodschap.txt
String saveFileName = saveFile;
// Stap 3..Bepaal MIME Type en de positie van eind mime type in string
voorbeeld: -----------------------------7d23d21220524 Content-Disposition: form-data; name="file0"; filename="C:\WINNT\Profiles\mvo\Desktop\z clob.txt" Content-Type: text/plain
String restant = "";
int pos; //position in upload file
// bijv .. filename="C:\Documents and Settings\Administrator\Desktop\boodschap.txt"
pos = file.indexOf("filename=\"");
//find position of content-disposition line
pos = file.indexOf("\n",pos)+1; // eing file naam + spatie
// onderstaand geeft bijv Content-Type: text/plain
restant = file.substring(pos,file.indexOf("\n",pos)-1);
restant = restant.substring(restant.indexOf(":")+2,restant.length()); // MIME type
String mimeType = restant;
//find position of eind content-type line
pos = file.indexOf("\n",pos)+1;
//find position of blank line
pos = file.indexOf("\n",pos)+1;
int start = pos;
// Stap 4 eind boundary
/*find the location of the next boundary marker (marking the end of the upload file data)*/
int boundaryLocation = file.indexOf(boundary,pos)-4; //waarom -4 ..? ziet er uit als linebreak spatie--boundary=-----------------------------7d21c9ae00f0
// Stap 5 en 6..de eigelijke te uploaden file in nieuwe byte file inserten
byte dataBytes2[] = new byte[boundaryLocation-start]; //declareren
for (int i=0;i<(boundaryLocation-start);i++) // inserten BELANGRIJK !!
dataBytes2=dataBytes[start+i];
String next_id = "0";
Statement statement = null;
Connection conn = null;
boolean pass = true;
ResultSet rs = null;
Statement stmt_empty = null;
oracle.sql.BLOB blb = null;
try
int vendor = DriverUtilities.ORACLE;
String username = ConnectionParams.userName;
String password = ConnectionParams.passWord;
String connStr = DriverUtilities.makeURL(vendor);
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
conn = DriverManager.getConnection(connStr,username, password);
if (conn==null){pass=false;}
} catch (Exception e){out.println("<P>" + "There was an error establishing a connection:");}
if (pass==true)
try
String seq_nextval ="select forum_blob_seq.nextval from dual";
statement = conn.createStatement();
ResultSet rset = statement.executeQuery(seq_nextval);
while (rset.next())
next_id = rset.getString(1);
if (next_id.equals("0"))
message = "Uploaden mislukt !...Er ging wat fout tijdens de interactie met de database";
responseRedirect = "/forum/uploaden.jsp?message="+message;
pass = false;
} catch (Exception e1) { out.println("Error blob1 : "+e1.toString()); };
} // end pass
if (pass==true)
try
Statement stmt2 = conn.createStatement();
String insert_empty_blob = "INSERT INTO test_blob(id "+
",filename "+
",mimetype "+
",kb) "+
"VALUES("+Integer.parseInt(next_id) +
",'"+saveFileName+"'"+
",'"+mimeType+"'"+
","+kb_size+")";
stmt2.executeQuery(insert_empty_blob);
conn.commit();
if (stmt2!= null) {stmt2.close();}else{stmt2.close();pass = false;}
} catch (Exception e2){
message = "Uploaden mislukt !...Er ging wat fout tijdens de interactie met de database";
responseRedirect = "/forum/uploaden.jsp?message="+message;
out.println("<P>" + "2. There was an error inserting mime type:");}
} //end pass
if (pass==true)
try
conn.setAutoCommit(false);
} catch (Exception e3) { pass = false; out.println("Error blob 3: "+e3.toString()); };
} //end pass
if (pass==true)
try
String Query_blob ="Select test_blob FROM test_blob where id="+next_id+" FOR UPDATE";
stmt_empty = conn.createStatement();
rs=stmt_empty.executeQuery(Query_blob);
} catch (Exception e4) {
pass = false;
out.println("Error blob 4: "+e4.toString());
message = "Uploaden mislukt !...Er ging wat fout tijdens de interactie met de database";
responseRedirect = "/forum/uploaden.jsp?message="+message;};
} //end pass
if (pass==true)
try
if (rs.next())
blb = ((OracleResultSet)rs).getBLOB(1);
OutputStream stmBlobStream = blb.getBinaryOutputStream();
try {
int iSize = blb.getBufferSize();
byte[] byBuffer = new byte[iSize];
int iLength = -1;
ByteArrayInputStream stmByteIn = new ByteArrayInputStream(dataBytes2);
try {
// while ( (iLength = in.read(byBuffer, 0, iSize)) != -1 )
while ( (iLength = stmByteIn.read(byBuffer, 0, iSize)) != -1 )
stmBlobStream.write(byBuffer, 0, iLength);
stmBlobStream.flush();
} // end while
} catch (Exception e5) {
pass=false;
out.println("Error blob 5: "+e5.toString());
message = "Uploaden mislukt !...Er ging wat fout tijdens de interactie met de database";
responseRedirect = "/forum/uploaden.jsp?message="+message; }
finally { conn.commit(); }
} catch (Exception e6) { out.println("Error blob 6: "+e6.toString()); };
} //end if rs.next()
else { throw new SQLException("Could not locate message record in database."); }
} catch (Exception e7) { out.println("Error blob : "+e7.toString()); };
} // end pass
} // end pass2
else //request is not multipart/form-data
message = "Uploaden mislukt !...Gegevens niet verstuurd via multipart/form-data.";
responseRedirect = "/forum/error.jsp?message="+message;
out.println("Request not multipart/form-data.");
catch(Exception e)
try
//print error message to standard out
out.println("Error in doPost: " + e);
//send error message to client
out.println("An unexpected error has occurred.");
out.println("Error description: " + e);
}catch (Exception f) {}
response.sendRedirect(responseRedirect);
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
doPost(request,response);
Regards
Martin -
How to add array of file types to file dialog box
Hi
I just want to know how to add array of file types in file dialog box vi. I know that multiple file type can be added to filedialog vi in the pattern Input string separated by semicolon (eg *.vi;*.doc;*.jpeg;*.xls). But i want file dialog which is shown in the below picture.
I think that file dialog vi call user32.dll but i don't have that header file to call that dll.
Waiting for your esteemed response.
Thanks & Regards
Samuel J
System Engineer
Captronic Systems Pvt Ltd
Bangalore, India.I'm not sure how (or even if) it can be achieved using the LabVIEW built-in open dialog, but a .NET call to openfiledialog (http://msdn.microsoft.com/en-us/library/system.windows.forms.openfiledialog.aspx) can do what you're looking for. The .NET functions are better documentented that simple user.dll calls, so it might be easier to implement.
Shaun -
How to add an audio file to a link
I am working on a project using IWeb and I am trying to figure out if it is possible and then, if it is how to add an audio file to a link. I would really be glad of your help as I am having problems meeting the requirements of the project if I don't make it work.
Also, is it possible when having added a movie clip from quick time player to have the clip start as soon as the page is "opening", that is without pressing the play button?
I am waiting in great suspense to see if anybody can help me out. If you have the answers to my questions, please send me an email at [email protected] - thank you so much :o)Hi Maiken
Welcome to the discussion forums.
All you need is open iWeb, select text or image, open inspector, go to link, check the "enable as a hyperlink" box, in "link to" there's a teardown menu where you select "a file" and select the file you want to link to.
If you want to have it downloading look at [this|http://alyeska.altervista.org/en/iWeb_Downloads.html]
For the second question:
select the movie file in iWeb go to inspector, then to the last icon (showing the quicktime logo) and check the box that say "Autoplay".
Regards,
Cédric -
How to add a Java file from ejbModule to EJBCandidates ?
Hi,
In my java client proxy project, I have got the EJBCandidates generated. But I need to add one more java source file from ejbModule to EJBCandidates.
If I right click on the java file I need to add, am not getting that option for adding.
<b>Please help me how to add java source file from ejbModule to the EJBCandidates.</b>
Thank you.Great... :-)
Thank you very very much xHacker :-)
That what just what I needed. -
Hi All,
How to add the property file..ie(default.properties) to a webdynpro project.
I urgently require the solution. Kindly get it for me.
Regards
DKHi DK,
this is described in the second Web Dynpro Java Tutorial
<a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/downloaditem?rid=/library/uuid/b1a3e990-0201-0010-aeb2-a2ef5bc3da8e">creating an Extended Web Dynpro Application</a>
Regards, Bertram -
How to add existing jsp file to a project?
I am trying out 10g developer preview. Looks like a lot of bugs are there in the tool. I would like to know how to add existing jsp file into a project. I tried the Import functionality, but it shows the option to create a project and include only Java files. Is there a way to do this? Thank you
Just copy the files in the directory where the rest of your source file is.
-
How to add SDK jar file in NWDS
Dear Friends,
Currently i have an issue. I have to bring the BO favorite to my Portal Screen. My Portal is developed in PDK.
I have few links where the source code is writhen. Those link's are
/people/michael.nicholls/blog/2010/02/22/using-the-pdk-to-access-businessobjects-infoview
http://wiki.sdn.sap.com/wiki/display/Snippets/ReadInfoViewfavoritesfromthe+portal
I don't know more about BO. I have few points which i mentioned below.
1) How to add SDK jar file in NWDS.
2)DO i need any specific package for that.
Kindly help me with your Valuble suggestion and document.
Thanx in Advance.
Prashant KrishenHi,
for adding all the jar files in NWDS fallow below steps
windows >> preferences >>Java>>Java buildpath>>Libraries>>add external jars
Hope this helps
Edited by: polaka123 on Nov 13, 2010 12:44 PM -
what file name is for the driver of gpib-usb-b?and how to add the driver file to vb in win2000??thanks
Hi,
Multiple files are required for the proer fnctioning of any of our GPIB products. Unfortunatly the installation is not as simple as copying a single file over. If you wish to make the installer silent, i believe this is entirely possible in a fashion similar to the details given at http://digital.ni.com/public.nsf/websearch/0730A66245E6808086256CA8006E2183?OpenDocument.
Hope this helps out!
Best Regards,
Aaron K.
Application Engineer
National Instruments -
Hi Friends,
We have 4 below file systems.
Sybase/TST/sapdata_1
Sybase/TST/sapdata_2
Sybase/TST/sapdata_3
Sybase/TST/sapdata_4
Already we have added one data file each in sapdata_1 and 2. Sapdata3 and 4 are emptry.
How to add new data file in sapdata3 or 4.
Please provide syntax for creating a new data file and steps for the same.
Regards,
Karthik.Just for the record: you have here the DBACockpit documentation:
https://websmp201.sap-ag.de/~form/sapnet?_FRAME=CONTAINER&_OBJECT=011000358700000571562012E
And this is a sample of the extend to be executed:
Regards,
Victoria. -
How to add a html file into JEditorPane
Hi
I am doing an aplication on swing.But I don't know how to add a html file to the JeditorPane keeping the html file on the source code. i.e my html file is in my source code.Then how to add this html file to Jeditor pane.
Thanks
SrikantQuickTime requires player and plugins that most people don't have. You'll reach a much wider audience if you use HTML5 <video> with mp4, webm and ogg files.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>HTML5 with Video</title>
<!--help for older IE browsers-->
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<style>
video {
max-width:100%;
display:block;
margin:0 auto;
</style>
<body>
<h2>Use 3 File Types to support all browsers & mobile devices: MP4, WEBM and OGV.</h2>
<h3>Online Video Converter
http://video.online-convert.com/</h3>
<!--begin video-->
<video controls poster="Your_poster_image.jpg">
<!--these are 6 sec sample videos for testing purposes. Replace sample-videos with your own files-->
<source src="http://techslides.com/demos/sample-videos/small.webm" type="video/webm">
<source src="http://techslides.com/demos/sample-videos/small.ogv" type="video/ogg">
<source src="http://techslides.com/demos/sample-videos/small.mp4" type="video/mp4">
If you're seeing this, you're using an
outdated browser that doesn't support
the video tag. </video>
<!--end video-->
</body>
</html>
Nancy O. -
How to add a quicktime file to a shake script?
Hi I just purchased Shake 4.1 and can't figure out for the life of me how to add another quicktime file as a node in a script I am working on.
Example:
The source node file I sent from FCP which I need to key and add the background image to.
How do I add the bg image?
Also does it have to be a image or can it be a movie file?As well as Thanks, you might give the Captain a few points in appreciation:
New Discussions ResponsesThe new system for discussions asks that after you mark your question as Answered, you take the time to mark any posts that have aided you with the tag and the post that provided your answer with the tag. This not only gives points to the posters, but points anyone searching for answers to similar problems to the proper posts.
If we use the forums properly they will work well...
Patrick -
HT201301 how to add app to file sharing list ?
how to add app to file sharing list ?
For expamle, i have autocad ws app on iPad. When i had previous version of iTunes i saw this program in file sharing list.
After upgrading iTunes AutoCad have gone from this list, how can I return this back?
Thank You.From what I read in the app description in iTunes on my computer, you need some sort of account and you use this with a desktop program as well. Files are uploaded to a server???
I see no mention of file sharing in the app description.
https://itunes.apple.com/app/autocad-ws/id393149734?mt=8
BTW, you cannot add an app to file sharing - it has to suppport file sharing on it's own - it must be built into the app. If the app supports file sharing, it will be in the file sharing apps list in iTunes. -
How to add a .mov file to i tunes
how to add a .mov file to i tunes
Export to master file. Use H.264 and in the When Done selection pick iTunes library or whatever.
-
How to add new music files in Hp connecterd music
I am new to HP connected music. I want to understand the following
a) Where does HP connected music app look for music in our computer. I want to know the location of folders.
b) How to add new music files into playlists
can anyone help please.
RAVIKUMAR RTHi @rtravikumar
I see you are looking for some help with HP Connected Music. I did a little bit of searching and found the following pages that should be useful to you.
HP Connected Music Powered by Meridian (Windows 8)
HP Connected Music FAQ
I hope this helps.
Malygris1
I work on behalf of HP
Please click Accept as Solution if you feel my post solved your issue, it will help others find the solution.
Click Kudos Thumbs Up on the right to say “Thanks” for helping!
Maybe you are looking for
-
Custon clearing agent vendor change in MIRO
Hi friends, I am having the issue. User makes an import PO (CIN4.0A version). in the PO, there is one main vendor who willl supply the goods, one vendor (Customs office) who will raise and send the customs excise invoice and one vendor as customs cle
-
All of a sudden my computer stopped allowing me to watch Youtube videos or anything involving Adobe Flash software. I tried uninstalling Flash and reinstalling it, I've tried changing my cookies... everything that I find on different forums and I sti
-
HI to all, can it possible if sms integration with sap business one. means if i create a/r invoice if i add the document automaticlly send sms to the customer in that sms following matter to be send invoice number,posting date,due date,invoice a
-
HT1535 how do i transfer music to my iPhone album/artist list from my playlist
only allowed to transfer music to my playlist on my iphone using itunes 11.1 ever since upgrading to 11.1... How do I get it to my regular music list on my iphone?
-
Orange LED while plugged in, but charging?
Hi. When my shuffle is plugged into my computer, and iTunes isn't open, there is an orange LED lit up above the control buttons, which, according to http://docs.info.apple.com/article.html?artnum=300657 means it is charging. And when I do open iTunes