• Post Reply Bookmark Topic Watch Topic
  • New Topic

Saving Text file at runtime  RSS feed

 
Suma kempegowda
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all ...
in my application i need to open text file and save it in any directory with " save as" option from File menu at run time . these "save as" should work in background with some other file extension like ".doc"
here i am having code to open file at runtime but not for save as ..
can please any one solve this ....
Thanks in advance


 
Greg Charles
Sheriff
Posts: 3014
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Suma,

Welcome to JavaRanch!

First, please use code tags when posting code. They make it much easier to read. Now, what you're doing here is opening a text file in Windows Notepad. Java really isn't doing anything for you. Is that what you meant to do? What do you mean "save as" should run in the background? Also, you can change the file extension to .doc if you want, but that doesn't convert it to a Word Doc. You understand that, right?
 
Suma kempegowda
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Greg Charles,
as youu told its working like this
public class Pageconvert extends HttpServlet
{

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
try
{
String filepath=request.getParameter("filecad");
Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec("C:/WINDOWS/system32/notepad.exe filepath");

InputStream in = new FileInputStream(new File(filepath));
OutputStream out1 = new FileOutputStream(new File("filepath"));
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0)
{
out1.write(buf, 0, len);
}
in.close();
out1.close();
File oldfile = new File(filepath);

int dotPos = filepath.lastIndexOf(".");
//String strExtension = oldfileExtension.substring(dotPos + 1);
String strFilename = filepath.substring(0, dotPos);
String newfileExtension = "doc";
String strNewFileName = strFilename + "." + newfileExtension;
File newfile = new File(strNewFileName);
boolean Rename = oldfile.renameTo(newfile);

if(!Rename) {
System.out.println("FileExtension hasn't been changed successfully.");
}
else
{
System.out.println("FileExtension has been changed successfully.");
}


}
catch(Exception e)
{
System.out.println("error:"+e);
}


}

}



actually i am trying for another application like autocad file like .dwg file to .dxf file conversion
so initially i am opening .dwg file in autocad software . then i want to save that .dwg file in .dxf file format that is available in file save as option ..
initially i am trying to open any file like .txt file its working fine ...
for save as option i am trying to work.
 
Tim Moores
Saloon Keeper
Posts: 3512
77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is very unlikely that you will be able to control a complex app from the command line; I'd read the documentation to see whether this is possible. It is also very unlikely that AutoCAD will be installed on the server where your servlet runs.
 
Suma kempegowda
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Moores wrote:It is very unlikely that you will be able to control a complex app from the command line; I'd read the documentation to see whether this is possible. It is also very unlikely that AutoCAD will be installed on the server where your servlet runs.


Hi Tim Moores,
if not for servelts ,is it work for console application in java ,where we can explicitly specify it .for file type for "save as " option from file menu .
in notepad .exe
 
Tim Moores
Saloon Keeper
Posts: 3512
77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since that would be a feature of the target application it doesn't matter how you try to access it. The target app either supports it or it doesn't.
 
Suma kempegowda
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Moores wrote:Since that would be a feature of the target application it doesn't matter how you try to access it. The target app either supports it or it doesn't.


yes we trying for this application first time .. with java coding ..
so we are trying with notepad as a test . if it works for notepad we will try to do it for autocad
any suggestions are welcome here to guide me ...
 
Tim Moores
Saloon Keeper
Posts: 3512
77
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suma kempegowda wrote:so we are trying with notepad as a test . if it works for notepad we will try to do it for autocad

That doesn't make sense. There is no standard for this amongst apps, so whether or not Notepad can do this proves exactly nothing about whether or not any other app can do it. In fact, Notepad being the lowly app it is, I can just about guarantee you that it can't do anything like this. A high-end commercial app like AutoCAD, OTOH, is much more likely to have scripting facilities, or an API. I'd start by reading its documentation on how to automate tasks in it, and whether it's even possible, before I'd write any code, though.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!