Append text in file. and save it
Append text in file.
hi!
i am new j2me Programer.
1.i want to add(APPEND) the text in the file. i take this code form internet but i could succed Please help me.
2.i want to save it in other directory like if i made folder on mobile device with name c:\Old i want to save file in that how could i ?
kindly mention the Mistake.
package FileConnection;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.io.*;
import javax.microedition.io.*;
* @author QTracker
public class FileConnection extends MIDlet implements CommandListener {
private boolean midletPaused = false;
private Command exit, start;
private Display display;
private Form form;
public FileConnection ()
display = Display.getDisplay(this);
exit = new Command("Exit", Command.EXIT, 1);
start = new Command("Start", Command.EXIT, 1);
form = new Form("Write To File");
form.addCommand(exit);
form.addCommand(start);
form.setCommandListener(this);
private void initialize() { }
public void startMIDlet() { }
public void resumeMIDlet() {/
public void switchDisplayable(Alert alert, Displayable nextDisplayable) {
Display display = getDisplay();
if (alert == null) {
display.setCurrent(nextDisplayable);
} else {
display.setCurrent(alert, nextDisplayable);
public Display getDisplay () {
return Display.getDisplay(this);
public void exitMIDlet() {
switchDisplayable (null, null);
destroyApp(true);
notifyDestroyed();
public void startApp() {
display.setCurrent(form);
public void pauseApp() {
midletPaused = true;
public void destroyApp(boolean unconditional) {
public void commandAction(Command c, Displayable d) {
if (c == exit)
destroyApp(false);
notifyDestroyed();
else if (c == start)
try
OutputConnection connection = (OutputConnection)
Connector.open("file:\\c:\\myfile.txt;append=true", Connector.WRITE );
OutputStream out = connection.openOutputStream();
PrintStream output = new PrintStream( out );
output.println( "This is a test." );
out.close();
connection.close();
Alert alert = new Alert("Completed", "Data Written", null, null);
alert.setTimeout(Alert.FOREVER);
alert.setType(AlertType.ERROR);
display.setCurrent(alert);
catch( ConnectionNotFoundException error )
Alert alert = new Alert(
"Error", "Cannot access file.", null, null);
alert.setTimeout(Alert.FOREVER);
alert.setType(AlertType.ERROR);
display.setCurrent(alert);
catch( IOException error )
Alert alert = new Alert("Error", error.toString(), null, null);
alert.setTimeout(Alert.FOREVER);
alert.setType(AlertType.ERROR);
display.setCurrent(alert);
}
| Moderator advice: | Please read the announcement(s) at the top of the forum listings and the FAQ linked from every page. They are there for a purpose. |
| | Please don't post in threads that are long dead and don't hijack another poster's thread. |
| | Please don't solicit off forum communication by email. |
| Moderator action: | The other four posts you made have been deleted. |
db
Similar Messages
-
Read multiple files and save all into one output file(AGAIN)
Hi, guys
I need your help for reading data from multiple files and save the results into one output file. When files are selected from file chooser, my program read the data line by line , do some calculations and save the result into the output. I made an array to store input files and it seems to be working fine, but when it comes to SaveFile() function, issues NullPointException message.
public class FileReduction1 extends JFrame implements ActionListener
// GUI definition and layout
/* ACTION PERFORMED */
public void actionPerformed(ActionEvent event) {
if (event.getActionCommand().equals("Open File")) getFileName();
/* OPEN THE FILE */
private void getFileName() {
// Display file dialog so user can select file to open
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
fileChooser.setMultiSelectionEnabled(true);
int result = fileChooser.showOpenDialog(this);
// If cancel button selected return
if (result == JFileChooser.CANCEL_OPTION) return;
if (result == JFileChooser.APPROVE_OPTION)
files = fileChooser.getSelectedFiles();
textArea.setText("");
if(files.length>0)
filelist="";
System.out.println("files length"+files.length);
for(int i=0;i<files.length;i++)
System.out.println(files.getName());
filelist+=files[i].getName()+" ,";
if (checkFileName(files[i]) )
openButton.setEnabled(true);
readButton.setEnabled(true);
textArea.append("file "+files[i].getName()+"is a proper file"+"\n");
readFile(files[i]);
textfield.setText(filelist);
else{JOptionPane.showMessageDialog(this,"Please select file(s)",
"Error 5: ",JOptionPane.ERROR_MESSAGE); }
// Obtain selected file
/* READ FILE */
private void readFile(File fileName_in) {
// Disable read button
readButton.setEnabled(false);
// Dimension data structure
getNumberOfLines(fileName_in);
data = new String[numLines][4];
// Read file
readTheFile(fileName_in);
// Rnable open button
openButton.setEnabled(true);
/* GET NUMBER OF LINES */
/* Get number of lines in file and prepare data structure. */
private void getNumberOfLines(File fileName_in) {
int counter = 0;
// Open the file
openFile(fileName_in);
// Loop through file incrementing counter
try {
String line = fileInput.readLine();
while (line != null) {
counter++;
System.out.println("(" + counter + ") " + line);
line = fileInput.readLine();
numLines = counter;
closeFile(fileName_in);
catch(IOException ioException) {
JOptionPane.showMessageDialog(this,"Error reading File",
"Error 5: ",JOptionPane.ERROR_MESSAGE);
closeFile(fileName_in);
System.exit(1);
/* READ FILE */
private void readTheFile(File fileName_in)
// Open the file
//int row=0;
int col=0;
openFile(fileName_in);
System.out.println("Read the file");
// Loop through file incrementing counter
try
String line = fileInput.readLine();
while (line != null)
boolean containsDoubles = false;
double temp;
String[] lineParts = line.split("\t");
try
for (col=0;col<lineParts.length;col++)
temp=Double.parseDouble(lineParts[col]);
data[row][col] = lineParts[col];
containsDoubles = true;
System.out.print("data["+row+"]["+col+"]="+lineParts[col]+" ");
} catch (Exception e) {row=0; col=0; temp=0.0;}
if (containsDoubles){ row++;}
System.out.println();
line = fileInput.readLine();
catch(IOException ioException)
JOptionPane.showMessageDialog(this,"Error reading File", "Error 5: ",JOptionPane.ERROR_MESSAGE);
closeFile(fileName_in);
System.exit(1);
//System.out.println("length"+data.length);
closeFile(fileName_in);
process(fileName_in);
/* CHECK FILE NAME */
/* Return flase if selected file is a directory, access is denied or is
not a file name. */
private boolean checkFileName(File fileName_in) {
if (fileName_in.exists()) {
if (fileName_in.canRead()) {
if (fileName_in.isFile()) return(true);
else JOptionPane.showMessageDialog(null,
"ERROR 3: File is a directory");
else JOptionPane.showMessageDialog(null,
"ERROR 2: Access denied");
else JOptionPane.showMessageDialog(null,
"ERROR 1: No such file!");
// Return
return(false);
/* OPEN FILE */
private void openFile(File fileName_in) {
try {
// Open file
FileReader file = new FileReader(fileName_in);
fileInput = new BufferedReader(file);
catch(IOException ioException) {
JOptionPane.showMessageDialog(this,"Error Opening File",
"Error 4: ",JOptionPane.ERROR_MESSAGE);
textArea.append("OPEN FILE\n---------\n");
textArea.append(fileName_in.getPath());
textArea.append("\n");
//System.out.println("File opened successfully");
/* CLOSE FILE */
private void closeFile(File fileName_in) {
if (fileInput != null) {
try {
fileInput.close();
catch (IOException ioException) {
JOptionPane.showMessageDialog(this,"Error Opening File",
"Error 4: ",JOptionPane.ERROR_MESSAGE);
System.out.println("File closed");
private void process(File fileName_in) {
//getNumberOfLines();
//data = new String[numLines][3];
// Read file
double temp,temp1;
//readTheFile();
//System.out.println("row:"+row);
//int number=data.length;
//System.out.println(number);
for (int i=0; i<row; i++)
temp=Double.parseDouble(data[i][1]);
sumx+=temp;
temp1=Double.parseDouble(data[i][3]);
sumy+=temp1;
multixy+=(temp*temp1);
square_x_sum+=(temp*temp);
square_y_sum+=(temp1*temp1);
//System.out.println("Sum(x)="+sumx);
double tempup=(row*multixy)-(sumx*sumy);
double tempdown=(row*square_x_sum)-(sumx*sumx);
slope=tempup/tempdown;
double tempbup=sumy-(slope*sumx);
intb=tempbup/row;
double tempside=(row*square_y_sum)-(sumy*sumy);
double cordown=Math.sqrt(tempdown*tempside);
corr=tempup/cordown;
r_sqrt=corr*corr;
textArea.append("Data for file"+ fileName_in.getName()+" have been processed successfully.");
textArea.append("\n");
textArea.append("Please enter output file name including extension.");
System.out.println("number"+row);
System.out.println("slope(m)="+slope);
System.out.println("intecept b="+intb);
System.out.println("correlation="+corr);
System.out.println("correlation="+r_sqrt);
saveFile();
private void saveFile()
textArea.append("SAVE FILE\n---------\n");
if (openFile1())
try {
outputToFile();
catch (IOException ioException) {
JOptionPane.showMessageDialog(this,"Error Writing to File",
"Error",JOptionPane.ERROR_MESSAGE);
private boolean openFile1 ()
// search for the file path
StringBuffer stringpath;
title=textfield1.getText().trim();
int temp=fileName_in.getName().length();
int temp_path=fileName_in.getPath().length();
int startd=(temp_path-temp);
stringpath=new StringBuffer(fileName_in.getPath());
stringpath.delete(startd, temp_path+1);
//System.out.println("file-path="+temp_path);
//System.out.println("length-file="+temp);
path=stringpath.toString();
fileName_out = new File(path, title);
//System.out.println(file_out.getName());
if (fileName_out==null || fileName_out.getName().equals(""))
JOptionPane.showMessageDialog(this,"Invalid File name",
"Invalid File name",JOptionPane.ERROR_MESSAGE);
return(false);
else
try
boolean created = fileName_out.createNewFile();
if(created)
fileOutput = new PrintWriter(new FileWriter(fileName_out));
fileOutput.println("File Name"+"\t"+"Slope(m)"+"\t"+"y-intercept(b)"+"\t"+"Coefficient(r)"+"\t"+"Correlation(R-Squared)");
return(true);
else
fileOutput = new PrintWriter(new FileWriter(fileName_out,true));
return(true);
catch (IOException exc)
JOptionPane.showMessageDialog(this,"Please enter the file name","Error",JOptionPane.ERROR_MESSAGE);
return(false);
private void outputToFile() throws IOException
// Initial output
textArea.append("File name = " + fileName_out + "\n");
// Test if data exists
if (data != null)
fileOutput.println(fileName_in.getName() +"\t"+ slope+"\t"+intb+"\t"+corr+"\t"+r_sqrt);
textArea.append("File output complete\n\n");
else
textArea.append("No data\n\n");
// End by closing file
initialcomp();
fileOutput.close();
private void initialcomp()
slope=0.0;
intb=0.0;
corr=0.0;
r_sqrt=0.0;
sumx=0.0; sumy=0.0; multixy=0.0; square_x_sum=0.0; square_y_sum=0.0;
for(int i=0;i<data.length;i++)
for(int j=0;j<data[i].length;j++)
data[i][j]=null;
/* MAIN METHOD */
public static void main(String[] args) throws IOException
// Create instance of class FileChooser
FileReduction1 newFile = new FileReduction1("File Reduction Program");
// Make window vissible
newFile.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
newFile.setSize(500,400);
newFile.setVisible(true);
Sorry about the long lines.
As you can see, all input files saved in array called files, however when OpenFile1() function is called, it take input (fileName_in) as a single file not an array. I'm assuming this causes the exception.
When there's muptiple inputs, program should take each file from getFileName() to outputToFile() sequentially.
Does anybody have an idea to solve this?
Thanks a lot!!you naming convention is confussing. you should follows Java naming convention..you have a getXXX but decalred the return type as "void"...get usully means to return something...
your code is doing too much..and hard to follows..
1. get the selected files
for each selected file
process the file and return the result
write out the result.
/** close the precious resource */
public void closeResource(Reader in){
if (in != null){
try{ in.close(); }
catch (Exception e){}
/** get the total number of line in a file */
public int getLineCount(File file) throws IOException{
BufferedReader in = null;
int lineCount = 0;
try{
in = new BufferedReader(new FileReader(file));
while ((in.readLine() != null)
lineCount++;
return lineCount;
finally{ closeResource (in); }
/** read the file */
public void processFile(File inFile, File outFile) throws IOException{
BufferedReader in = null;
StringBuffer result = new StringBuffer();
try{
in = new BufferedReader(new FileReader(inFile));
String line = null;
while ((in.readLine() != null){
.. do something with the line
result.append(....);
writeToFile(outFile, result.toString());
finally{ closeResource (in); }
public void writeToFile(File outFile, String result) throws IOException{
PrintWriter out = null;
try{
out = new PrintWriter(new FileWriter(outFile, true)); // true for appending to the end of the file
out.println(result);
finally{ if (out != null){ try{ out.close(); } catch (Exception e){} } }
} -
Which Version of Adobe do I need to be able to "extract" a page from a existing file and save/download to another file?
Acrobat Pro or Standard.
-
How to use cfdocument create a PDF file and save the file in server?
Hi,
I want to use cfdocument to create a PDF file and save it in
the server for other people to download,can you give me a idea how
to do this.Thanks.
<cfdocument format = "PDF" pagetype="A4"
orientation="portrait">
</cfdocument>
MarkHi
<cfdocument filename="" format = "PDF" pagetype="A4"
orientation="portrait">
</cfdocument>
Give the physical path to the filename. You have write
permission for this folder to create a PDF file. -
To upload file and save it in a location
Hi,
I need to upload an image file in database. and also save a copy of this uploaded image file in a particular location. If updating the image file, then i need to remove the previous image file and save the new one against a particular record.
I did to upload. i want to save a new file and remove the previous file. how to do this?
Thanks in advanceHi,
Hope this help
https://cn.forums.oracle.com/forums/thread.jspa?threadID=983109
ADF Faces Intermedia image upload and Display
http://baigsorcl.blogspot.com/2010/08/uplaoding-and-downloading-images-in.html
http://baigsorcl.blogspot.com/2010/09/store-images-in-blob-in-oracle-adf.html
~Abhijit -
What Steps do I take to edit raw files and save for web use, such as Instagram, Facebook, Websites, and emailing?
When you open a raw file it will open in Adobe camera raw. That is where you can do most of the editing. Then it will be placed inside Photoshop where you can do more if needed.
Now you can use the save for web dialog to export your image as a png or jpg to use on those sites. -
I have allready bought the programs, but need to reinstall AE and PP due to an error with dynamic link.
Where do i find the program install?
And tips on how to reinstall without messing things up?
last question is, does my recent files and saves work after the reinstall?
Thank youkarianne wrote:
I have allready bought the programs, but need to reinstall AE and PP due to an error with dynamic link.
Where do i find the program install?
Which versions? Which operating system?
Try Download and Installation Help -
How to tell script colse all files and save, but no untitle docs
Hi everyone
I want to colse the open files and save them but no those files which have never been saved.
I try this script but after ran, all the files are no be saved.
var docs = app.documents;
for (var i = docs.length-1; i >= 0; i--) {
if(app.activeDocument.saved == false){
docs[i].close(SaveOptions.NO);
else if(docs[i].close(SaveOptions.YES));
can someone tell me what's wrong with the script?
thanks
Regard
Teetanvar docs = app.documents;
for (var i = docs.length-1; i >= 0; i--) {
if (docs[i].saved == false) {
docs[i].close(SaveOptions.NO);
else {
docs[i].close(SaveOptions.YES); -
Best way to modify a WMV file and save to computer
I have a 200 MB WMV file for a 4 hour meeting presentation. I want to split it up and save it into 4 separate 1 hour presentations. With a little editing in the middle to remove breaks and downtimes.
I can do everything but the Save. Whenever I save it, it either is in really poor quality and 50 MB or it is okay quality and 500-5000 MB. Quality doesn't have to be great but I should be able to read 12 point text when expanding it to full screen.
How do I get my final copy to be of equal quality as the original and proportionallly small file size.I agree with Steve. While WMV is a supported format, the CODEC's used will initially heavily-compress the footage, and require some intense horsepower to internally convert to that DV-AVI.
Were I faced with your Project, WMM would be my first stop. If I needed Effects, or more editing capabilities, then I would convert that WMV to DV-AVI externally, Import that, but would probably Export/Share to DV-AVI, and use the free MS Media Encoder (name just recently changed, so my link no longer works with for the new version), as PrE (and PrPro) is not the ultimate WMV Encoder.
Remember, your material is already heavily-compressed, and no amount of conversion, whether internally, or externally, will recover the lost data and quality. Keeping things in WMV with WMM will keep it as good as it gets, and that is why Steve, and I, recommend it for this sort of Project. WMV's are great for delivery, but heck to edit.
Good luck,
Hunt -
Is there an easy way to take a layered Id cc file and save and open in an older Ps?
I am trying to proof and edit a book being made at a school where they are using Id cc. I do not have Id, and am trying to figure out how they can save the layered file to send me and open in Ps or Ai. All I see is converting to a pdf file but it seems complicated to keep the layers as is. They tried sending me pdf files and neither Ps or Ai will open them. And not sure if they saved in layers. Any help is greatly appreciated!
Lilred wrote:
If I upgrade to Ps cc…
Just to be clear, you are asking about Photoshop cc? I don't see how that would be a good choice in editing InDesign files. You would need to have the school send you a PDF that you would need to open in Photoshop, which would rasterize all of the text, making it uneditable. I've never tried to edit anything with text in Photoshop, so if there is a way to keep the live type, I'm not aware of it, but even if you could keep live type, Photoshop's text abilities are very basic. InDesign is what you really need to use, and if the school has CC files, I don't see any way you can edit files that they could use without using InDesign CC. At the very least, you would need to use some version of InDesign, if not the CC version, but then you would have to deal with the problems that can happen when sharing files of different versions.
And if you are considering editing with Illustrator, your type will likely break apart. I made an example that I'm posting as a screenshot.
I copied a paragraph of my response to you, pasted into InDesign, exported as a PDF, then opened the PDF in Illlustrator. The upper paragraph is live, and the lower is the Illustrator that I placed below. They look the same, but I have changed the color of the live type (after the export) to show you how it breaks apart. The first magenta bit is one text fragment. When the font changes to bold, it creates a new fragment (shown in green), then a third (in blue) when it goes back to Roman. The whole second line (in yellow) has been converted to outlines, so I can't edit it at all. If I wanted to remove two of the magenta words and insert 5 different words, the rest of the line wouldn't flow. That's what you're up against if you edit with Illustrator.
ID is the only real choice, and if they have CC, you should be using CC. -
Append text through File Connection JSR-075
Hi all and thank you in advance.
Can I append text to a text file which resides in an expansion card? I need the data inside the file to be preserved until I delete the file and the text I enter each time to be writen at the end of the file and stay there.
Any help would be appreciated.| Moderator advice: | Please read the announcement(s) at the top of the forum listings and the FAQ linked from every page. They are there for a purpose. |
| | Please don't post in threads that are long dead and don't hijack another poster's thread. |
| | Please don't solicit off forum communication by email. |
| Moderator action: | The other four posts you made have been deleted. |
db -
Scripting to replace a layer in a psd file and save as a tiff for multiple images in a sequence
I have over a hundred images, all the same size, that I need bring into photoshop as a designated layer, one at a time, flatten the image and save as a tiff file with a sequential number, then repeating the process. I have not used javascript before but it seems like it should work. I'm using CS5. Thanks
It is possible to do that via Scripting.
If you are unable to create such a Script maybe you should look up the chapter »Creating data-driven graphics« in the documentation. -
I have a form that I am sending out and compiling in the response file. These forms I also want to be able to update after receiving them (when I have them in the response file).
But when I do the updates I need to re-save the response file with another name? The strange thing is that sometimes I can just update and save exactly the way I want it. But most of the time I get the message "This file may be read-only, or another user may have it open. Please save the document with a different name or in a different folder."
Can someone please help me to figure out how to solve this issue. I know that I am the only one that has the file open. I am encountering the same issue in both Acrobat Pro 9 and Acrobat Pro X. (File was created in Acrobat Pro 9)Good day!
A simple Paste does not work for you?
It should place the clipboard content as a new Layer which you can then move around.
If there is any chance that the elements need to be scaled, rotated etc. I would prefer to place them as Smart Objects (File > Place …) and do the masking that is specific to the images themselves in those.
Regards,
Pfaffenbichler -
Close ALL open files and save jpg with jpg option
Hi,
I have some (a lot) of -jpg images to crop, and resize, while I have to do this one by one based on what portion of the image to crop, once done I need to close, and save them.
To speed up the process I open several files, and do the crop&resize, and when finished I use "close all", and would like to avoid to confirm the "save" dialogue, and the "jpeg options" "image quality option" dialogue, having to say save, and the option set to a given value.
Unfortunatelly I am not a coder, and didn't understand anything from the Javascript Scripting Reference guide.
I found this
app.docRef.close(SaveOptions.SAVECHANGES);
here, I pasted it into ExtendScript, saved it, but when opening the script from file > scripts > browse it returns error 21 (undefined is not an object)
Will you please kindly give me the script?
Thank youAdd this snippet to a script file.
Load script file in PS scripts folder
Restart photoshop
Assign keyboard shortcut to script
#target photoshop
//Make Photoshop the formost Appplication
app.bringToFront();
// Requires at least one open document
while (app.documents.length > 0)
//Save all open windows
{activeDocument.close(SaveOptions.SAVECHANGES);} -
How to sign a pdf file and save it directly back to sharepoint site?
Hello,
I own a Sharepoint site for testing. It is installed in my computer with Sharepoint 2010 (WSS). What I want to do is to find a way to achieve a signing function for pdf file type on sharepoint.
By refer to this site below, the site has been able to recognize pdf file type and open it and edit it directly on the sharepoint site.
http://www.portalsolutions.net/Blog/Lists/Posts/Post.aspx?ID=40
I can edit the pdf file by checking out and then the modification will be save directly back to the pdf file in the shared document library when I am done. Now the problem is, I cannot save the pdf directly back to sharepoint after I inserted a digital signature
to the pdf file.
Everytime I inserted a digital signature to the pdf file, a "save as..." window would pop up and asked me to save the signed pdf file as another file in my local computer, so the changes were not applied to the original pdf file on the shared document library
of my sharepoint site. I have to upload the local signed version back to the site and replace the old one manually.
Any suggestion? Thank you.
Mengxin Wu
Hi,
According to my analysis, for Digital Signatures: Adobe has changed the behavior around digital signatures and SharePoint-hosted PDF files. Now, when digitally signing a SharePoint-hosted PDF file, it will be saved directly to SharePoint if that PDF file
is already checked out. If not, the user will be prompted to check it out. When digitally signing a SharePoint-hosted PDF file in Acrobat X, Version 10.0, the user would be prompted to save that file locally and would then need to upload it separately to SharePoint
as a new version.
I suggest that you use Acrobat X, then check the result. For more information about Acrobat X, please refer to
http://blogs.adobe.com/pdfitmatters/2011/06/whats-new-in-acrobat-x-version-10-1.html
In addition, you can also consider the following third-party tool:
http://www.arx.com/digital-signature/sharepoint
Thanks,
Rock Wang
Maybe you are looking for
-
Everytime i open Iphoto it says "loading photos" but never does. i hev to close it down. Next time I oen it the same thing happend. This started after I downloaded some photos from a media card through my HP1600 printer. Part way through the download
-
Why can charging our devices get so complicated?
For some people, depending on their charging needs, usually based on the number of devices they need to charge can get very confusing. Here are some scenarios. After which if there is any one that can provide some insight in how to charge devices usi
-
Is Mac's firewall sufficient or is will an additional firewall help? What security suite do you recomend for MacBook Air with Maverick?
-
Which Overclock is better?
I havce manged to stay stable at a 1:1 of 3.2ghz, and also at 3.5ghz with the memory turned down to settings of 333mhz. Which overclock is better? thanxs, oh and wat is the best air cooler out there?
-
Need debugging help: Why is JScrollPane auto-scrolling?
I'm trying to figure out why when I double-click on a cell within a JTable that's wrapped in a JScrollPane in order to open up another window, the JScrollPane automatically scrolls to the top. Even when I update the double click operation to simply c