Using textarea to write data to html files
Hi. I am trying to make an application to change contents of html files. I used filereader and filewriter constructors but I guess I have a problem with using textarea. I want the data from the file to appear in a textarea so I can edit it and save.
boolean saveFile () {
JTextArea textarea = new JTextArea();
JFrame frame = new JFrame();
frame.add(textarea);
File file = null;
File fFile = new File ("default.java");
JFileChooser fc = new JFileChooser ();
htmlFilter fhtmlFilter = new htmlFilter();
// Start in current directory
fc.setCurrentDirectory (new File ("."));
// Set filter for Java source files.
fc.setFileFilter (fhtmlFilter);
// Set to a default name for save.
fc.setSelectedFile (fFile);
// Open chooser dialog
int result = fc.showSaveDialog (this);
if (result == JFileChooser.CANCEL_OPTION) {
return true;
} else if (result == JFileChooser.APPROVE_OPTION) {
fFile = fc.getSelectedFile ();
return writeFile (file,textarea.getText);
return true;
// saveFile
boolean openFile () {
htmlFilter fhtmlFilter= new htmlFilter();
File file = new File("");
JTextArea textarea = new JTextArea();
JFileChooser fc = new JFileChooser ();
fc.setDialogTitle ("Open File");
// Choose only files, not directories
fc.setFileSelectionMode ( JFileChooser.FILES_ONLY);
// Start in current directory
fc.setCurrentDirectory (new File ("."));
// Set filter for Java source files.
fc.setFileFilter (fhtmlFilter);
// Now open chooser
int result = fc.showOpenDialog (this);
if (result == JFileChooser.CANCEL_OPTION) {
return true;
} else if (result == JFileChooser.APPROVE_OPTION) {
file = fc.getSelectedFile ();
JFrame frame= new JFrame();
frame.add(textarea);
frame.pack();
frame.setVisible(true);
// Invoke the readFile method in this class
return writeFile (file, textarea.getText ());
return true;
} // openFile
public static boolean writeFile (File file, String dataString) {
try {
PrintWriter out =
new PrintWriter (new BufferedWriter (new FileWriter (file)));
out.print (dataString);
out.flush ();
out.close ();
catch (IOException e) {
return true;
} // writeFile
public String readFile(File file)
JFrame frame= new JFrame();
JTextArea textarea = new JTextArea();
frame.add(textarea);
StringBuffer contents = new StringBuffer();
//declared here only to make visible to finally clause
BufferedReader input = null;
try {
//use buffering, reading one line at a time
//FileReader always assumes default encoding is OK!
input = new BufferedReader( new FileReader(file) );
String line; //not declared within while loop
* readLine is a bit quirky :
* it returns the content of a line MINUS the newline.
* it returns null only for the END of the stream.
* it returns an empty String if two newlines appear in a row.
while (( line = input.readLine()) != null){
System.out.println(line);
catch (FileNotFoundException ex) {
ex.printStackTrace();
catch (IOException ex){
ex.printStackTrace();
finally {
try {
if (input!= null) {
//flush and close both "input" and its underlying FileReader
input.close();
catch (IOException ex) {
ex.printStackTrace();
return contents.toString();
}
Sorry this didn't get a response sooner. You can alter the way your consumer loop writes the data to file by altering the data that you send through the queue. I would suggest clustering your data (the array you currently send) with an array of booleans. Then you can unbundle this cluster in the consumer loop before you write to file and use it accordingly. This should allow you to do what you're trying to do.
Just to give you some feedback on your code, there are few things that you can improve upon. I'm sure this is a learning process so you probably know a lot more about LabVIEW now than you did when you started.
All of your array operations in there can be done much simpler. You have a whole Index Array node that inputs 8-21 in order. This can be done by simply having an 8 at the beginning and dragging the rest down since the indices always count from the previous by default. You are also doing a lot of indexing and re-building of arrays. You should look int o Array Subset VI and Array To Cluster node to consolidate here.
You have a lot of indicators and controls that coudl be consolidated in to array and/or clusters. Your "element 1", "element 2", etc indicators are all displayed on the front panel next to each other, so why not just display them as an array?
You use property nodes in a couple places to read the values. This can be better done by a local variable. Property nodes shouldn't usually be read from continuously.
Similar Messages
-
How to write data to text file using external tables
can anybody tell how to write data to text file using external tables concept?
Hi,
Using external table u can load the data in your local table in database,
then using your local db table and UTL_FILE pacakge u can wrrite data to text file
external table
~~~~~~~~~~~
http://download-east.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_7002.htm#i2153251
UTL_FILE
~~~~~~~~~
http://download-east.oracle.com/docs/cd/B19306_01/appdev.102/b14258/u_file.htm#sthref14093
Message was edited by:
Nicloei W
Message was edited by:
Nicloei W -
How to Write data in Excel File using java
Hi
can anybody help me to write data in excel file
using java code
Thankx In AdvanceHow much are you willing to pay for that?
If you want it for free, http://jexcelapi.sourceforge.net/ -
Write data to a file in OBPM 11g
How to write data to a file in OBPM 11g?
I want to capture all the data from the begin of an instance through the end. Please let me know how to do it.
Thanks in advance..Hi Dharwat,
Thanx for your answer. That class you mentioned needs an instream and an outstream. I have only an outstream.
My program produces a normal ascii report data, but i must write into a file in UTF-16 format (that's what the customer want
I know also class CL_ABAP_CONV_OUT_CE, but i don't know how to use it for an UTF-16 output.
I hope someone can expain me very clearly how it works for an UTF-16 together with the open dataset statement.
Thanx anyway.
Gr., Frank
Edited by: F. Bernsen on Nov 17, 2008 12:46 PM -
Can I use Photoshop Elements 13 to create HTML file?
Can I use Photoshop Elements 13 to create HTML file?
See Barbara's answer in your duplicated post: How can I save a Photoshop Elements 12 file as HTML?
No difference with PSE13. -
How to write data to xml file?
Hi,
I have done a project which read data from a web then write in log file.
Now i want to write data in xml file.
how to write?
i read some java and xml tutorial, quite quite difficult.
Who can give a simple example with some comments?
If you also give some tips on learning java web services, i will be very appreciated.
Thanks
Yang BinChoose Xerces2.4 to serialize the DOM object is an option.
javac XercesTest.java -classpath xmlParserAPIs.jar;xercesImpl.jar;.
java -classpath xmlParserAPIs.jar;xercesImpl.jar;. XercesTest test.xml
below is the source file: XercesTest.java
//JAXP
import javax.xml.parsers.*;
import org.w3c.dom.*;
//APACHE SERIALIZE FUNCTION
import org.apache.xml.serialize.*;
class XercesTest
public static void main(String[] args) throws Exception
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse( new File( args[0] ) );
File f = new File( "copy_of_"+ args[0] );
OutputFormat format = new OutputFormat("xml","UTF-8",true ) ;
FileOutputStream fout = new FileOutputStream( f );
XMLSerializer ser = new XMLSerializer(fout, format );
ser.serialize( doc );
hope it's helpful
land -
Data Acquisition - using local variables to write data to a file
Hello,
I am running a Data Acquisition vi (currently in LabVIEW 7.1 but soon to be updated to 8.2) that collects ~100 parameters of data from several sources contained in a while loop. The current configuration (which I did not write) uses very few subVIs and writes to ~100 local variables to store each parameter. It then reads all the local variables and builds an array of all the strings, converts then to a spreadsheet string, then uses the write characters to file function to append to a datafile. I am trying to clean things up and have came up with subVIs to collect the data from the following sources:
8 serial port sources collecting btwn 8 and 20 parameters each
~15 thermocouple readings
~10 analog inputs
~20 parameters read off an ARINC 429 bus.
I have come up with a subVI to read each of the sources and have placed the subVIs in the while loop. Each subVI outputs the data that it collects in array or cluster form. I was wondering how best to write each parameter to a CSV file at between 1 and 10 Hz. Should I write each subVI output to a LV and then read them off as was done before (the difference being that I have reduced the # of LVs to ~10 vs >100?
I should add that precise timing is not that important, so if all the subVIs are not collecting simultaneously (which I understand that they won't be), it does not really matter.
Thanks.Hi jilla,
jilla wrote:
What I think that you are saying is to turn the outputs of the 4 subVIs into inputs of a 5th subVI that writes to the data file. Correct?
Yes. It may sound like a fine-point, but I beileve it's better to create a VI specifically for formatting data - in your example, 4 arrays IN, a single string OUT. Then write the string to file as a seperate operation. GUI-displayed data can go through a similar transformation, the four arrays wired to a subVI which builds output-structures specifically for display. It's a beginner's mistake to put lots of individual controls and indicators on the screen when groups of them are naturally related (in an object-oriented sense.) Use clusters to group related controls - this will keep the diagram much cleaner.
One more question: at what point (either # of data points or frequency of data collection) does it become necessary to use queues? Thanks.
Well, there's not really a clearly definable "point". I'd say if your update-rate climbs above 100Hz, or you witness poor program or system performance, then it's time. The scenario you've described is a fairly simple acquire/display&log loop - and simple is good. Then-again people can't see/react-to updates faster than about 10Hz - so it doesn't make sense to sacrifice performance - if performance becomes an issue.
Re: queues: Queues are sometimes used to buffer data that's "produced" in one place and "consumed" in another.
Here, if/when logging data, you're logging with every DAQ. I wouldn't recommend using a queue to transport data from a "DAQ loop" to a "Logging-loop" - those functions can be in the same loop. Should/could a queue be used to get data from a "DAQ loop" to update the GUI at a lower frequency? Sure, but a Notifier might be a better choice. Further, in the (simple?) program you've described, you might use a case structure (True/False) to only update FP indicators every "X" iterations - a simple solution that doesn't require Queues or Notifiers.
Cheers!
"Inside every large program is a small program struggling to get out." (attributed to Tony Hoare) -
Use Java to collect data from HTML
Hi Guys
I am doing a online stock trading project, the main part is to collect raw data from http://finance.yahoo.com User can retrieve the stock detail by inputting the right stock symbol, such as "AOL". I dont have too much problem in this part because yahoo provde a spreedsheet format to display the result. If you type the URL below, it can bring you a set of stock data separating by comma. So, I can use StringTokenizer(date, ",") to collect each data from yahoo into my system.
========================================================================
http://finance.yahoo.com/d/quotes.csv?f=sl1d1t1c1ohgv&e=.csv&s=AOL&
"AOL",15.57,"8/12/2003","4:01pm",+0.04,15.47,15.63,15.40,12097200
========================================================================
However beside this function, I also need to search Stock Symbol, because user may only know the company name. Although Yahoo finance also provide this function, with no spreedsheet format provided. So, if I type the URL below, it will only give me a set of result BUT in HTML format.
========================================================================
http://finance.yahoo.com/l?s=AOL&t=S&m=
========================================================================
So, can anyone tell me what is the best way to collect data from a HTML page? Or anyone know any good stock quoting sites which also provide spreedsheet format?
Thank you very much
KelI am doing a online stock trading project, the
the main part is to collect raw data from
http://finance.yahoo.com
Sounds fun.
So, can anyone tell me what is the best way to
to collect data from a HTML page? Or anyone know any
good stock quoting sites which also provide
spreedsheet format?I really don't know any other stock quote sites. But if you want to implement a search function for stock names, I would do it like this
1) Code the HTTP SUBMIT/POST to lookup the possible stock names
2) Use XSL to filter out the HTML path to the table with results, the layout is consistent, so there are no strange exceptions. You can check the DOM structure by using Mozilla's DOM inspector. Just write down the path to the TABLE element and select it, and transform it to CSV for example.
3) Reparse the CSV to fill some boxes
To possibly save some server load use a small fixed size in memory cache to store N requests based on some strategy.
The other part is actual a separate part of what you want to code and should be a separate class in which you can feed the stock name.
If the user types in a bad stock name, you can retrieve a list of possible names using the input as the company name.
Greets.
Maybe there is a SOAP service out there somewhere. -
Hi
I want to write data from a string into a file. I am created a directory and a .doc file . But when i write this data from a string into .doc file , its give an error : File not found exception
But, when i check in my directory, a file is created with blank.
My code is:
import java.io.*;
import java.util.*;
import java.lang.*;
class createFile {
public static void main(String[] args) {
try {
String mss = "This is for dedo";
FileInputStream fis;
FileOutputStream fos;
File file = new File("C:\\JD\\m4.rtf");
// Create file if it does not exist
boolean success = file.createNewFile();
success = true;
if (success) {
System.out.println("suc");
fis = new FileInputStream(mss);
System.out.println(fis);
fos = new FileOutputStream(file);
int c;
while ((c = fis.read()) != -1) {
fos.write(c);
System.out.println("mss");
fis.close();
fos.close();
System.out.println("created");
// File did not exist and was created
} else {
// File already exists
} catch (IOException e) {
System.out.println(e);
regards
madhuInputStream inputStream = new ByteArrayInputStream(mss.getBytes());Use this to push into the file>
Ummm.... no. InputStreams are for reading, not for writing.
Anyway, OP, you're making a mistake. You're trying to open a stream to a file called "This is for dedo". Use FileOutputStream(File file) constructor or FileOutputStream(String pathToFile). You can then wrap that stream with a PrintWriter or whatever you need. -
How to read and write data from json file from windows phone7 app
Hi
I am developing wp7 app for the use of students my questions are
How can i write a code to read and write the json/text file for the wp7.
I am using windows 7 OS, VS 2010 Edition.
This is my code below:
xaml:
<Grid>
<TextBlock Height="45" HorizontalAlignment="Left" Margin="7,18,0,550" Name="textBlock1" Text="Full
Name: " />
<TextBox Width="350" Height="70" HorizontalAlignment="Left" Margin="108,1,0,0" Name="txtName"
Text="Enter your full name" VerticalAlignment="Top" />
<TextBlock Height="45" HorizontalAlignment="Left" Margin="6,75,0,0" Name="textBlock2" Text="Contact
No: " VerticalAlignment="Top" />
<TextBox Width="350" Height="70" HorizontalAlignment="Left" Margin="108,61,0,480" Name="txtContact"
Text="Enter your contact number" MaxLength="10" />
<Button Content="Register" Height="72" HorizontalAlignment="Left" Margin="10,330,0,0" Name="btnRegister"
VerticalAlignment="Top" Width="190" Click="btnRegister_Click" />
</Grid>
xaml.cs:
private void btnRegister_Click(object sender, RoutedEventArgs e)
string name, contact;
name = txtName.Text;
contact = txtContact.Text;
try
if (name != "" && contact != "")
string msg = name + " " + contact;
MessageBox.Show(msg);
Student stud = new Student
Name= name,
Contact = contact,
string jsonString = JsonConvert.SerializeObject(stud);
MessageBox.Show(jsonString);
else
MessageBox.Show("Input Proper Information", MessageBoxButton.OK);
catch (Exception ex)
MessageBox.Show(ex.Message);
I have download NewtonSoft.json version 5.0.8.
So, I am able to convert input data into json format, but how can I able to write and read this data from a json/text file.
How can I do?
Thank you in adv and please, reply soon.We don't have many samples left for Windows Phone 7 + Azure, the closest one to what you want to do is probably:
Using Local Storage with OData on Windows Phone To Reduce Network Bandwidth
this sample uses the local database feature: 'LINQ to SQL', available to Windows Phone 7.1 and 8.0 Silverlight applications, instead of simple file storage but even if you choose to stick with simple file storage I believe you should be able to adapt the
networking related portions of the sample to your particular application.
Eric Fleck, Windows Store and Windows Phone Developer Support. If you would like to provide feedback or suggestions for future improvements to the Windows Phone SDK please go to http://wpdev.uservoice.com/ where you can post your suggestions and/or cast
your votes for existing suggestions. -
Write data to .txt file with formatting
Hi,
I am trying to read data from serial port and write it on to a .txt file. I am able to write onto the file but it has got no formatting. What I would ideally like to do is, read the data from serial port, take only some parts of it and write on to the text file with proper formatting. Also, I would like to use the same file to append data each time. I am also having issues setting the pointer to EOF. I would like to append to end of file.
This is my sample data
18:33:23 02/10/10 28.32 0 LAC 0.378 mg/dL 0000\
18:33:23 02/10/10 28.32 0 GLU 102 mg/dL 0000
that is being read from the serial port. From this I would like to take only columns 1,2,3,5,6 and write onto the .txt file.
Can someone provide some pointers? I'm using Labview 6.1
Thanks,
SukanyaIf you know what "charecters" you don't want it is pretty easy. A little more difficult when they are unwanted only in certain places in the string. There is a remove whitespace function in the string functions palette. There is also a search and replace function in the "additional string functions" subpalette, that can be set up to find all instances of a char and replace it with something else, an empty string if you want to just delete it/them from your string.
Putnam
Certified LabVIEW Developer
Senior Test Engineer
Currently using LV 6.1-LabVIEW 2012, RT8.5
LabVIEW Champion -
Unable to write data into excel file when it's close
Hi,
I'm facing this problem and it's a bit weird. I'm using the following method to insert data into excel file. But when excel file is close, it unable to write data into the excel sheet. But it was able to write the data into the excel sheet if i open the excel file when running the program.
Can anyone please tell me what's wrong to the code?
public int updateLog(String sheet, String no, String cpId, String CatId, String rbtCode, String rbt, String rbtName, String artistName, String price, String rbtFileName, String songId, String msg){
int result = -1;
try{
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss",Locale.ENGLISH);
String actionDate = formatter.format(new Date());
rbtName = rbtName.replaceAll("'", "''");
artistName = artistName.replaceAll("'", "");
String sql = "insert into [Sheet3$] (Code, CpID, CategoryID, RBTCode, RBT, RBTName, ArtistName, Price, RBTFileName, SongID, UploadStatus, FileUploadedDateTime) ";
sql = sql + " values ('" + no + "', '" + cpId + "', '" + CatId + "', '" + rbtCode + "', '" + rbt + "', '" + rbtName + "', '" + artistName + "', '" + price + "', '" + rbtFileName + "', '" + songId + "', '" + msg + "', '" + actionDate + "')";
System.out.println(sql);
log.writeLog(sql);
result = stmnt.executeUpdate(sql);
} catch(Exception e){
e.printStackTrace();
log.printStackTrace(e);
return result;
public int openConnection(){
int result = -1;
try{
Class.forName(dbDriver);
c = DriverManager.getConnection(conStr + excelFilePath+";ReadOnly=0;");
stmnt = c.createStatement();
} catch(Exception e){
e.printStackTrace();
log.printStackTrace(e);
return -1;
return 1;
}ThanksHI,
i hv a doubt regarding reading / opening of a
password protected Excel file using jxl( java ) .
How to read / open a password protected Excel file
thro Java (jxl ) program .plz let me know some
example also .
Regards,
Ramesh P
845935822cross posting !! answered here
http://forum.java.sun.com/thread.jspa?threadID=710466&messageID=9507085#9507085 -
As in the title. l have revived a couple of old VIs to read and write three numbers and a 1D array of clusters to/from a *.txt file. The functionality is not very user friendly, and it would also be useful if one could open the text files (manually - not through LabVIEW) and still be able to see/understand what was there.
I was wondering if anyone would be able to come up with a more efficient and/or user friendly method (compatible with lv6.1)
James
Never say "Oops." Always say "Ah, interesting!"
Attachments:
Read Spec.vi 110 KB
Write Spec.vi 58 KBMy primary goal is to have something that works and is easy and comprehensive to operate. Generating a human-readable file is just a bonus but would be nice if it could be achieved.
I enclose pictures of the initial file dialog (for both loading and saving the data - referred to as Spec(s) from hence forth), and of the front panel screen seen when a) loading a spec and b) saving a spec. In the file dialog, you have to already know the exact string to input else you'll just be told the file doesn't exist (applies for both loading and saving). When saving a spec, you cannot see any files previously saved, nor even any previous specs saved within the file. This means that one can unwittingly overwrite specs without realising it.
I'm not sure if I've explained this very well, but the current functionality means that far too much can go wrong. Additionally, if you forget the file name, you'll have no way of knowing what it should be (the data files are stored on a 'locked' part of our network accessible only by Admin or through the LabVIEW executable
Never say "Oops." Always say "Ah, interesting!"
Attachments:
File Dialog.JPG 23 KB
Select The Required Test Spec.JPG 10 KB
Name of specification.JPG 6 KB -
Write data to Text file - Column by Column
Hi,
I want to write a table of data(2D) to a text file. I acquire 1D array(6 lakh rows) of data & want to write that in text file as column 0. And next 1D array to the same text file as column 2. Is it possible todo that?
I don't want to accumulate 2D array and write at last since it consumes more memory & Labview Hangs.
Kindly share your ideas.....
Labview 8.2
Regards,
RajaHI,
I hope this works for you but this vi doesnt hanged my PC or Labview. Please check with it and let me know.
Regards,
Gita
Message Edited by AutoTEC on 10-17-2008 04:15 AM
Attachments:
Write column by column.vi 1398 KB -
Hi ,
I have a question regarding writing data in a text file. I have a lot of classes which are having lot of println statements. Can we send data to a file which are coming from different classes. I need to update file in sequencial way which are coming from different classes. I tried it . but it doesn't stored. can anyone rectify me.
here is sample code ;
in main method
try {
BufferedReader inFile = new BufferedReader(new FileReader(fileName));
PrintWriter out = new PrintWriter(new FileWriter("OutFile.txt"));
// calling classA methods
// calling classB methods
out.close();
inFile.close();
catch (IOException e) {
System.exit(1);
classA
public void method1()
out.println(" message from classA - method1 ");
public method2()
out.println(" message from classA - method2");
classB
public void method1()
out.println(" message from classB - method1 ");
public method2()
out.println(" message from classB - method2");
} I need to call different methods in different times and update in a text file. can we do it ? Can anyone give suggestions for me.
Thanks in advance,
-balajiboss u r doing it a wrong way
try this way
create a method
for writing file and pass a string parameter like this
public void createLog(String data)
try
FilwWriter f=new FileWriter(new File("output.txt"))
f.write(data)
f.close();
catch(Exception e)
and whichevr class u want to enter data in text file just call this method
createLog(" message from classA - method2");
createLog(" message from classA - method1")
createLog(" message from classB - method3")
Maybe you are looking for
-
Error installing itunes on windows xp a network error occurred
i have trouble installing iTunes 10.2.2 on WIndows XP computer. Everytime i get message that a network error occurred. What is the trouble here? Any help is appreciated!
-
Reverse engineering using Flat file
Hello, Can someone help me please. My environment, I am new to ODI and trying to work with it. My source DB = FLAT FILE Target DB = MySQL5.1 I created a new project and models. I have the physical and logical architecture and all the connections are
-
Hey everyone, Ok, so I started having some issues last week with Kernel panics on Start up, on this thread here. http://discussions.apple.com/thread.jspa?threadID=1161960&tstart=0 I've tried almost every possible trouble shooting tip I could find wit
-
80710092 error code while trying to update Minecraft
Hi, While trying to update Minecraft version 1.17, my ps3 keeps getting an error code or freezing on 0%, 80710092. I have checked all connections and tried all manner of fixes from the internet but nothing has worked. I have re-booted both the PS3 an
-
Issue exporting original & virtual copies
I am using Lightroom 3.6 and do the following: - I selsect a photo "test.cr2" and rate it 2 stars - create a virtual copy of this photo and modify it (the virtual copy) and rate it 3 stars Now I use different Export settings to export my 2 stars and